NJsonSchema
NJsonSchema copied to clipboard
Error when resolving links in external file
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?
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"