RicoSuter/NJsonSchema
Ver no GitHubValidation fails on nested references in schema
Open
#1.301 aberto em 15 de jan. de 2021
help wantedproject: NJsonSchematype: bug
Métricas do repositório
- Stars
- (1.578 stars)
- Métricas de merge de PR
- (Nenhuma PRs mesclada em 30d)
Description
This was discovered by using PowerShell 7 (It worked in Powershell 6) which uses this library.
The following test will fail (if put in SchemaTests.cs), because there are nested levels of $ref.
The test will be green if the definition of bar is changed from ""$ref"": ""#/myDefs/barType"" to ""type"": ""string""
I can submit a PR, if I get a little hint about where these references are resolved. (or even just submit this test as an PR)
[Fact]
public async Task When_property_name_is_double_ref_then_validation_works()
{
//// Arrange
var jsonSchema = @"
{
""$schema"": ""http://json-schema.org/draft-07/schema#"",
""myDefs"": {
""barType"": { ""type"": ""string"" },
""fooType"": {
""type"": ""object"",
""properties"": {
""bar"": { ""$ref"": ""#/myDefs/barType"" }
}
}
},
""type"": ""object"",
""properties"": {
""foo"": { ""$ref"": ""#/myDefs/fooType"" }
}
}";
var jsonContent = @"
{
""foo"": {
""bar"": ""Something""
}
}";
//// Act
var validator = new JsonSchemaValidator();
var schema = await JsonSchema.FromJsonAsync(jsonSchema);
var result = validator.Validate(jsonContent, schema);
//// Assert
Assert.Empty(result);
}
Failure message:
Result StackTrace:
at NJsonSchema.JsonSchema.GetActualSchema(IList`1 checkedSchemas) in C:\NJsonSchema\src\NJsonSchema\JsonSchema.Reference.cs:line 100
at NJsonSchema.JsonSchema.get_ActualSchema() in C:\NJsonSchema\src\NJsonSchema\JsonSchema.Reference.cs:line 23
at NJsonSchema.Validation.JsonSchemaValidator.ValidateProperties(JToken token, JsonSchema schema, String propertyName, String propertyPath, List`1 errors) in C:\NJsonSchema\src\NJsonSchema\Validation\JsonSchemaValidator.cs:line 360
at NJsonSchema.Validation.JsonSchemaValidator.Validate(JToken token, JsonSchema schema, String propertyName, String propertyPath) in C:\NJsonSchema\src\NJsonSchema\Validation\JsonSchemaValidator.cs:line 92
at NJsonSchema.Validation.JsonSchemaValidator.ValidateProperties(JToken token, JsonSchema schema, String propertyName, String propertyPath, List`1 errors) in C:\NJsonSchema\src\NJsonSchema\Validation\JsonSchemaValidator.cs:line 360
at NJsonSchema.Validation.JsonSchemaValidator.Validate(JToken token, JsonSchema schema, String propertyName, String propertyPath) in C:\NJsonSchema\src\NJsonSchema\Validation\JsonSchemaValidator.cs:line 92
at NJsonSchema.Validation.JsonSchemaValidator.Validate(JToken token, JsonSchema schema) in C:\NJsonSchema\src\NJsonSchema\Validation\JsonSchemaValidator.cs:line 73
at NJsonSchema.Validation.JsonSchemaValidator.Validate(String jsonData, JsonSchema schema) in C:\NJsonSchema\src\NJsonSchema\Validation\JsonSchemaValidator.cs:line 63
at NJsonSchema.Tests.Validation.SchemaTests.When_property_name_is_double_ref_then_validation_works() in C:\NJsonSchema\src\NJsonSchema.Tests\Validation\SchemaTests.cs:line 492
Result Message: System.InvalidOperationException : The schema reference path '#/myDefs/barType' has not been resolved.