I am testing NJsonschema and found following simple Json schema is invalid.
The original schema is a big schema contains a lot of definitions, one of the definitions (ResourceList) is a list contains a lot of other definitions, but to simplify the question, I have simplified the whole schema as below jsonschemastr in which only contains 4 definitions.
The problem is if the schema is defining the type (either ValueSet or CodeSystem) which is also contained in ResourceList, the whole schema will be invalid, but no problem if it is defining ValueSet1, why? Btw, my schema is valid and checked with other Json schema tools.
[Fact]
public async Task When_ref_is_nested_then_it_should_be_resolved()
{
/// Arrange
var jsonschemastr = @"{
""$schema"": ""http://json-schema.org/draft-04/schema#"",
""$ref"": ""#/definitions/ValueSet"", "//<=== Could not resolve this path, but it is valid with ValueSet1!!!
+@"""definitions"": {
""ResourceList"": {
""oneOf"": [
{
""properties"": {}
},
{
""$ref"": ""#/definitions/CodeSystem""
},
{
""$ref"": ""#/definitions/ValueSet""
}
]
},
""CodeSystem"": {
},
""ValueSet"": {
},
""ValueSet1"": {
}
}
}";
var schema = await JsonSchema4.FromJsonAsync(jsonschemastr);
/// Assert
var jsonOutput = schema.ToJson();
Assert.NotNull(jsonOutput);
}