NJsonSchema icon indicating copy to clipboard operation
NJsonSchema copied to clipboard

Error when resolving links in external file

Open dinar007007 opened this issue 1 year ago • 1 comments

Hello!

The error occurs if a external file contains a ref to an object from the same external file. Error text - System.InvalidOperationException: Could not resolve the path '#/myInt' Examples:

njsonschema.json

{
    "type": "object",
    "properties": {
        "bar": {
            "$ref": "./common.json#/myObject"
        }
    }
}

common.json

{
    "myObject": {
        "type": "object",
        "properties": {
            "myIntProp": {
                "$ref": "#/myInt"
            }
        }
    },
    "myInt": {
        "type": "integer"
    }
}

If I add the following definition to the njsonschema.json file, then the schema is read successfully

...
	"definitions": {
		"collection": {
			"$ref": "./common.json"
		}
	}

I don't understand something in the JSON schema standard or, for now, such resolution of refs is not supported in NJsonSchema?

dinar007007 avatar Dec 05 '23 10:12 dinar007007

The referenced document must also be a valid json schema file and common.json is not (ie "myObject" is not a valid property of the root object)... you'd need to put the collection of definitions in "definitions":

{
   "definitions": {
       "myObject": {
          ...
       }
   }
}

and reference it via "./common.json#/definitions/myObject"

RicoSuter avatar Dec 08 '23 13:12 RicoSuter