Skip to content
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

Unable to Validate JSON Schemas #1667

Open
James-King-Shell opened this issue Jan 17, 2024 · 0 comments
Open

Unable to Validate JSON Schemas #1667

James-King-Shell opened this issue Jan 17, 2024 · 0 comments

Comments

@James-King-Shell
Copy link

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:

image

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

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant