Closed lukeocodes closed 7 years ago
Hello,
You have "required": true
in multiple parts of your schema. The required
keyword requires an array specifying what properties are required; you can't nest it under individual properties.
If you get an InvalidSchemaException you can check your schema against the draft-4 meta schema. https://github.com/yuloh/json-guard-cli makes that a little easier. The exception also has a pointer to the part of the schema that caused it, so you can catch it to get more info:
try {
$errors = $validator->errors();
} catch (League\JsonGuard\Exception\InvalidSchemaException $e) {
var_dump($e->getPointer(), $e->getKeyword());
}
Validating it using the justinrainbow/json-schema it validates fine, but json-guard works with other much more complex schema's that json-schema struggles with, especially with remote refs.
It also validates online using jsonschemavalidator.net against the above schema and payload.
Neither of those validators seem to check the schema itself, they just ignore invalid parts of the schema. https://jsonschemalint.com will actually check the schema itself.
The id
keywords in the schema are also invalid for Draft-4. They should be URIs. Make sure you read the links below because the id
will change how dereferencing works.
The schema is stored in a temporary file as it appears Deferencer requires a schema Uri.
You can dereference an object, but it needs to be json_decoded as an object, not an array and you can't use relative references without IDs. Otherwise it won't know where the URI is relative to and it won't be able to resolve the reference. For example, if your schema contains {"$ref": "./other-schema.json"
it can't resolve that without knowing where you initially loaded the schema from.
Hopefully that helps. Let me know if you have any further questions.
Great, thanks. I think this is a json-schema draft's version error. They work to draft-03 I believe. It's a vendor schema, so my hands are slightly tied.
:+1: thanks for your help.
We have a larger framework for consuming APIs, so by the time we attempt to validate we have the schema body. In this particular example the schema is actually behind oauth as well, which is helpful.
The schema is stored in a temporary file as it appears Deferencer requires a schema Uri.
When it runs I get
With the message
The Schema: https://pastebin.com/6njYBf70
The data payload:
Validating it using the
justinrainbow/json-schema
it validates fine, butjson-guard
works with other much more complex schema's thatjson-schema
struggles with, especially with remote refs.It also validates online using jsonschemavalidator.net against the above schema and payload.
Any ideas?
Update: I get the same exception without
Referencer
.