Core meta schema validation
In my project, I need to validate the JSON scheme itself. I made an example of an erroneous scheme that produces an error here, if selected "Schema Draft V7".
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"name": {
"type": 2
}
}
}
this code does not throw an error (set of validation messages is empty)
// param schema contains the error example above
public void validateSchema(ObjectNode schema) {
JsonSchemaFactory validatorFactory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(V7))
.objectMapper(objectMapper)
.build();
JsonSchema jsonSchema = validatorFactory.getSchema(schema);
Set<ValidationMessage> messages = jsonSchema.validate(schema);
log.info("" + messages);
}
For scheme draft V7, I can specify the core meta scheme, but I do not know how to do this for scheme draft 2019-09, since it consists of several vocabularies.
For each draft version, there is a meta schema. You can use it to validate the schema you are created. It is not common practice to validate the schema each time before using it to validate a JSON object.
Please refer to this question and let me know if you still have questions.
https://github.com/networknt/json-schema-validator/issues/285
Thank you, I read this issue. I do not create a custom meta scheme, but use the standard for draft 2019-09. Could you give an example of the code, how can I specify a standard meta scheme for 2019-09? My problem is that the meta scheme for this version, taken from here https://json-schema.org/specification.html#meta-schemas, consists of several linked json files.
As it is discussed in the mentioned issue, there is no difference when using meta schema to validate a schema. You just need to treat the meta schema as the schema input and your scheme file as the JSON object.
okay. The meta scheme for version 2019-09 contains several vocabularies whose definitions are physically located in different json files: Core Vocabulary meta-schema Applicator Vocabulary meta-schema Validation Vocabulary meta-schema Format Vocabulary meta-schema Content Vocabulary meta-schema Meta-Data Vocabulary meta-schema
Does the library support vocabularies? How do I load everything into an JSON object?
Hey @BigCheese83 how did you manage to solve it? I'm having the same issue.
@stefanondisponibile #475 identifies a work-around until we add support for vocabularies.
Thank you @fdutton !
@fdutton The bundled 2019-09 draft meta schema: https://gist.github.com/gareth-robinson/815239b36e397e484b77141b912d1b28, in https://github.com/networknt/json-schema-validator/issues/475#issuecomment-976306236 was very helpful for validating json schema against meta schema. Could you also provide a similar json for 2020-12 draft ?