Skip to content

Error during schema validation #376

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
sruedel-dotsource opened this issue Mar 10, 2017 · 5 comments · May be fixed by erasys/openapi-php#17
Closed

Error during schema validation #376

sruedel-dotsource opened this issue Mar 10, 2017 · 5 comments · May be fixed by erasys/openapi-php#17

Comments

@sruedel-dotsource
Copy link

I have the following schema:
{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "oneOf": [ { "properties": { "localeId": { "type": "integer" }, "answer": { "type": "string" }, "inputs": { "type": "array", "items": { "type": "object", "$ref": "#/definitions/inputs" } } }, "required": [ "localeId", "answer" ] }, { "properties": { "answerId": { "type": "integer" }, "inputs": { "type": "array", "items": { "type": "object", "$ref": "#/definitions/inputs" } } }, "required": ["answerId"] } ], "definitions": { "inputs": { "properties": { "id": { "type": "integer" }, "value": { "type": "string" } }, "required": [ "id", "value" ] } } }

If I want to validate data, the JsonSchema\SchemaStorage::resolveRef were called with parameter "#/definitions/inputs". The problem is that JsonPointer returned an empty filename in JsonSchema\SchemaStorage::addSchema and the uriRetriever try to get contents from a empty file which runs into an error.

@erayd
Copy link
Contributor

erayd commented Mar 10, 2017

I'm happy to deal with this one - already trapping the error in 39569bf. Will go hunting for the root cause and squash it this weekend.

@erayd
Copy link
Contributor

erayd commented Mar 10, 2017

For anyone else following along, here's the schema from the original comment, with nicer formatting:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "oneOf": [
        {
            "properties": {
                "localeId": {
                    "type": "integer"
                },
                "answer": {
                    "type": "string"
                },
                "inputs": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$ref": "#/definitions/inputs"
                    }
                }
            },
            "required": [
                "localeId",
                "answer"
            ]
        },
        {
            "properties": {
                "answerId": {
                    "type": "integer"
                },
                "inputs": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$ref": "#/definitions/inputs"
                    }
                }
            },
            "required": [
                "answerId"
            ]
        }
    ],
    "definitions": {
        "inputs": {
            "properties": {
                "id": {
                    "type": "integer"
                },
                "value": {
                    "type": "string"
                }
            },
            "required": [
                "id",
                "value"
            ]
        }
    }
}

@erayd
Copy link
Contributor

erayd commented Mar 10, 2017

Document that reproduces the bug:

{
    "answerId": 5,
    "inputs": []
}

erayd added a commit to erayd/json-schema that referenced this issue Mar 10, 2017
In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.
@erayd
Copy link
Contributor

erayd commented Mar 10, 2017

Fixed in #378.

bighappyface pushed a commit that referenced this issue Mar 17, 2017
#378)

* Add provided schema under a dummy / internal URI (fixes #376)

In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.

* Remove dangling use

* Change URI to class constant on SchemaStorage
@bighappyface
Copy link
Collaborator

#378 is merged, this will be official in 6.0.0

erayd added a commit to erayd/json-schema that referenced this issue Mar 17, 2017
…rainbow#376) (jsonrainbow#378)

* Add provided schema under a dummy / internal URI (fixes jsonrainbow#376)

In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.

* Remove dangling use

* Change URI to class constant on SchemaStorage
erayd added a commit to erayd/json-schema that referenced this issue Mar 17, 2017
…rainbow#376) (jsonrainbow#378)

* Add provided schema under a dummy / internal URI (fixes jsonrainbow#376)

In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.

* Remove dangling use

* Change URI to class constant on SchemaStorage
bighappyface pushed a commit that referenced this issue Mar 22, 2017
* Add URI translation for retrieval & add local copies of spec schema

* Add use line for InvalidArgumentException & adjust scope (#372)

Fixes issue #371

* add quiet option (#382)

* add quiet option

* use verbose instead of quiet

* add quiet option

* always output dump-schema

* always output dump-schema-url

* fix typo and ws

* [BUGFIX] Add provided schema under a dummy / internal URI (fixes #376) (#378)

* Add provided schema under a dummy / internal URI (fixes #376)

In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.

* Remove dangling use

* Change URI to class constant on SchemaStorage

* Add option to disable validation of "format" constraint (#383)

* Add more unit tests (#366)

* Add test coverage for coercion API

* Complete test coverage for SchemaStorage

* Add test coverage for ObjectIterator

* Add exception test for JsonPointer

* MabeEnum\Enum appears to use singletons - add testing const

* Don't check this line for coverage

mbstring is on all test platforms, so this line will never be reached.

* Add test for TypeConstraint::validateTypeNameWording()

* Add test for exception on TypeConstraint::validateType()

* PHPunit doesn't like an explanation with its @codeCoverageIgnore...

* Add various tests for UriRetriever

* Add tests for FileGetContents

* Add tests for JsonSchema\Uri\Retrievers\Curl

* Add missing bad-syntax test file

* Restrict ignore to the exception line only

* Fix exception scope

* Allow the schema to be an associative array (#389)

* Allow the schema to be an associative array

Implements #388.

* Use json_decode(json_encode()) for array -> object cast

* Skip exception check on PHP versions < 5.5.0

* Skip test on HHVM, as it's happy to encode resources

* Enable FILTER_FLAG_EMAIL_UNICODE for email format if present (#398)

* Don't throw exceptions until after checking anyOf / oneOf (#394)

Fixes #393

* Fix infinite recursion on some schemas when setting defaults (#359) (#365)

* Don't try to fetch files that don't exist

Throws an exception when the ref can't be resolved to a useful file URI,
rather than waiting for something further down the line to fail after
the fact.

* Refactor defaults code to use LooseTypeCheck where appropriate

* Test for not treating non-containers like arrays

* Update comments

* Rename variable for clarity

* Add CHECK_MODE_ONLY_REQUIRED_DEFAULTS

If CHECK_MODE_ONLY_REQUIRED_DEFAULTS is set, then only apply defaults
if they are marked as required.

* Workaround for $this scope issue on PHP-5.3

* Fix infinite recursion via $ref when applying defaults

* Add missing second test for array case

* Add test for setting a default value for null

* Also fix infinite recursion via $ref for array defaults

* Move nested closure into separate method

* $parentSchema will always be set when $name is, so don't check it

* Handle nulls properly - fixes issue #377

* Add option to also validate the schema (#357)

* Remove stale files from #357 (obviated by #362) (#400)

* Stop #386 sneaking in alongside another PR backport
erayd added a commit to erayd/json-schema that referenced this issue Mar 22, 2017
…rainbow#376) (jsonrainbow#378)

* Add provided schema under a dummy / internal URI (fixes jsonrainbow#376)

In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.

* Remove dangling use

* Change URI to class constant on SchemaStorage
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants