RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.4k stars 535 forks source link

No C# code generated for this JSON schema #297

Open r-pankevicius opened 7 years ago

r-pankevicius commented 7 years ago

Hi, I'm trying to generate serialization classes for this draft-04 schema, url is http://namespace.lantmateriet.se/distribution/produkter/registerbeteckning/v4/registerbeteckning-4.0.0.json.

Generator generates a single class without any attributes. Generator code:

class Program
{
    static void Main(string[] args)
    {
        string schemaUrl = "http://namespace.lantmateriet.se/distribution/produkter/registerbeteckning/v4/registerbeteckning-4.0.0.json";
        GenerateFromUrl(schemaUrl).Wait();
    }

    private async static Task GenerateFromUrl(string schemaUrl)
    {
        JsonSchema4 jsonSchema = await JsonSchema4.FromUrlAsync(schemaUrl);
        var settings = new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco, Namespace = "ns" };
        CSharpGenerator generator = new CSharpGenerator(jsonSchema, settings);
        string str = generator.GenerateFile("Foo");
        Console.WriteLine(str);
    }
}

Is there something wrong with this JSON schema or generator doesn't support some features?

wangzq commented 7 years ago

Same for the ARM json schema from #298: after temporarily modified the code to workaround an issue in the json schema bug, it loaded all the linked json schemas in 15 seconds without exception (as it appears), but the generated code is empty.

r-pankevicius commented 7 years ago

I'm not so sure it's JSON pointer issue as in #298 . I see all references have / after # in this file, e.g. "$ref": "#/definitions/response". I tried to invoke Validate on schema:

JsonSchema4 jsonSchema = await JsonSchema4.FromUrlAsync(schemaUrl);
string json = jsonSchema.ToJson();
var errors = jsonSchema.Validate(json).ToArray();
if (errors.Length > 0)
{
    Console.WriteLine($"Hey, we got {errors.Length} errors in schema!");
    for (int i = 0; i < errors.Length; i++)
    {
        Console.WriteLine($"=== Error {i+1}:");
        Console.WriteLine(errors[i]);
    }
}

I got 1 error that I don't know how to interpret:

NotAnyOf: #/
{
  NotAllOf: #/
  {
    NotAllOf: #/
    {
      PropertyRequired: #/type
      PropertyRequired: #/features
    }
    {
      PropertyRequired: #/type
    }

  }
  {
  }

}
{
  ArrayExpected: #/
}
{
  ArrayExpected: #/
}
{
  ArrayExpected: #/
}
{
  PropertyRequired: #/code
  PropertyRequired: #/reason
  PropertyRequired: #/errors
}