When attempting to validate a JSON schema itself using the JSON Schema schema or meta-schema e.g. from https://json-schema.org/draft/2020-12/schema, an error occurs when loading this schema into NJsonSchema due to an issue with the const keyword in a referenced schema.
Repro
var schemaJson = @"
{
""$id"": ""https://example.com/person.schema.json"",
""$schema"": ""https://json-schema.org/draft/2020-12/schema"",
""title"": ""Person"",
""type"": ""object"",
""properties"": {
""firstName"": {
""type"": ""string"",
""description"": ""The person's first name.""
},
""lastName"": {
""type"": ""string"",
""description"": ""The person's last name.""
},
""age"": {
""description"": ""Age in years which must be equal to or greater than zero."",
""type"": ""integer"",
""minimum"": 0
}
}
}";
// Load this schema
var schema = await JsonSchema.FromJsonAsync(schemaJson);
// Load the JSON Schema schema using the schema version e.g. https://json-schema.org/draft/2020-12/schema
var metaSchema = await JsonSchema.FromUrlAsync(schema.SchemaVersion);
// Validate the JSON schema using the meta schema
var validator = new JsonSchemaValidator();
var result = validator.Validate(schemaJson, metaSchema);
The line JsonSchema.FromUrlAsync(schema.SchemaVersion); results in the following exception:
The problem seems to arise from the meta/validation referenced schema which, when NJsonSchema resolves and attempts to load it. blows up when it encounters const: true
When attempting to validate a JSON schema itself using the JSON Schema schema or meta-schema e.g. from https://json-schema.org/draft/2020-12/schema, an error occurs when loading this schema into NJsonSchema due to an issue with the
const
keyword in a referenced schema.Repro
The line
JsonSchema.FromUrlAsync(schema.SchemaVersion);
results in the following exception:The problem seems to arise from the
meta/validation
referenced schema which, when NJsonSchema resolves and attempts to load it. blows up when it encountersconst: true