-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation of JSON-Schema #353
Comments
I don't think the library has that built-in, but if you want to set that up in your own code you might have a look at the files in |
@o5 you can validate it yourself using the validator and the json-schema schema $validator->validate(json_decode($schema), (object)['$ref' => 'http://json-schema.org/draft-04/schema']); |
Hello @mathroc, I'm sorry for my late response. I'm trying to use validate feature: $schema = json_decode('{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"id": {
"type": "number"
},
"type": "object"
}
}');
$validator = new Validator();
$validator->validate(
$schema,
(object) ['$ref' => 'http://json-schema.org/draft-04/schema#'],
Constraint::CHECK_MODE_VALIDATE_SCHEMA
); I'm expecting some error like Error parsing schema, but none given. Am I missing something? |
You're asking it to validate the schema, and the schema is valid (it's the official draft-04 meta-schema). That isn't an error condition.
|
@erayd: sorry, the snippet should be this :) $value = (object) [
'id' => 10,
];
$schema = json_decode('{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"id": {
"type": "number"
},
"type": "object"
}
}');
$validator = new Validator();
$validator->validate($value, $schema, Constraint::CHECK_MODE_VALIDATE_SCHEMA); I'm expecting error like in validator: |
@o5 Thanks - have reproduced this, and it does look like there's a bug somewhere. I'll get see if I can nail down the root cause today. |
Found it - there's an issue with object validation where Fixing this bug causes parts of the draft-04 test suite to fail - it looks like there is another bug that this one was hiding... |
...and the second bug is a result of fixing the first bug. The root cause is the library attempting to use the same variable for two different things:
I'll push a combined fix for both bugs hopefully sometime today (it's 12:22pm here). |
Object validation attempts to use a single variable to store both the object definition, and its properties. This causes validation to be incomplete where "properties" is not set, but "additionalProperties" is. This commit fixes both bugs in issue jsonrainbow#353.
Object validation attempts to use a single variable to store both the object definition, and its properties. This causes validation to be incomplete where "properties" is not set, but "additionalProperties" is. This commit fixes both bugs in issue #353.
Object validation attempts to use a single variable to store both the object definition, and its properties. This causes validation to be incomplete where "properties" is not set, but "additionalProperties" is. This commit fixes both bugs in issue jsonrainbow#353.
* Split $objectDefinition into $schema and $properties (#411) Object validation attempts to use a single variable to store both the object definition, and its properties. This causes validation to be incomplete where "properties" is not set, but "additionalProperties" is. This commit fixes both bugs in issue #353. * Issue-414: Allow The Option of T or space for Date time. (#415) * Testcase for minProperties with properties defined (#416) + Fix Test * Tweak phpdocumentor dependency to avoid install conflicts (#421) * [BUGFIX] Cast empty schema arrays to object (#409) * Cast root to object * Use function_exists to allow polyfill compatibility * Move array->object conversion to SchemaConstraint & SchemaStorage Fixes issue #408 * fix bug when applying defaults for array items when the schema is for (#405) all items and add support for minItems when applying defaults * [BUGFIX] Split "uri" format into "uri" & "uri-reference", fix meta-schema bug (#419) * Split "uri" format into "uri" and "uri-reference" * Correct format for id & $ref in draft-03/04 meta-schemas See json-schema-org/JSON-Schema-Test-Suite#177 (comment)
I would like to confirm that it works in version 5.2.1. Thank you! |
Most welcome :-). |
Am I missing something or there is not validation of schema itself? I don't know if it is possible, but it would be nice to throw something like json-schema parse error.
For json-schema:
I've expected similar error message as I got from jsonschemavalidator.net:
The text was updated successfully, but these errors were encountered: