0

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);
}
Bochen Lin
  • 413
  • 4
  • 12
  • Maybe my mind isn't seeing this correctly, but how could this possible be correct? ` @"{ ""$schema"":` Of course, this could be an XY question... Like why do it this way at all, when using a JSON library could serialize this and be much more legible and your odds of getting a valid JSON back better... – Austin T French Nov 11 '18 at 23:01
  • Looks like a bug, please create an issue in the NJsonSchema GitHub repo – Rico Suter Nov 15 '18 at 22:25
  • Created issue #807 [https://github.com/RSuter/NJsonSchema/issues/807] – Bochen Lin Nov 18 '18 at 03:32

0 Answers0