RicoSuter / NJsonSchema

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

System.InvalidOperationException: Could not resolve the JSON path when trying to create c# code from json schema #1550

Open mhording opened 2 years ago

mhording commented 2 years ago

Im using the schema found at http://namespace.lantmateriet.se/distribution/produkter/fastighetsamfallighet/v3/fastighet-samfallighet-3.0.0.json and trying to generate c# code from it.

It allways crashes on the external references it seems, with this error message: System.InvalidOperationException: Could not resolve the JSON path 'http://namespace.lantmateriet.se/distribution/produkter/fault/v1/fault-1.0.json#/definitions/fault' with the full JSON path 'http://namespace.lantmateriet.se/distribution/produkter/fault/v1/fault-1.0.json#/definitions/fault'. ---> System.InvalidOperationException: Could not resolve the path '#/definitions/fault'

This message is from nswag, but i got basically the same message when i tried to use the njsonschema nuget package to generate code from this schema.

Should the package not be able to resolve external references?

lahma commented 2 years ago

Might be related https://github.com/RicoSuter/NJsonSchema/pull/1098 , but the test case for that external reference resolving does pass...

lahma commented 2 years ago

Can the problem be that the http://namespace.lantmateriet.se/distribution/produkter/fault/v1/fault-1.0.json#/definitions/fault seems to be self-referencing?

$ref": "#/definitions/fault",

mhording commented 2 years ago

Thats a bit odd. I have mailed the providers of the schema and asked them if this is correct.

mhording commented 2 years ago

I got a response now. They are saying "the only reference in the fault schema is the root, which is refering to a section in the schema where the fault object is defined. It s an unneccesary extra step, since the schema only contains one object which itself could be placed under the root, but it is not an error".

corredor28 commented 10 months ago

Just a reminder to my future self: remember to look at the inner exception. In my case, the external referenced schema was not valid.