I want to validate a JSON against a JSON schema with Ajv in JavaScript. I get the error:
throw new it.MissingRefError(it.baseId, $schema, $message); ^ Error: can't resolve reference #/definitions/requestGraph from id requestGetGraphs
When removing reference to other schema: { "$ref" : "#/definitions/requestGraph" } the error disappears.
JavaScript-code:
ajv.addSchema(require('./json-schema/graph-response'), 'graph-response.json');
ajv.validate('requestGetGraphs', `{"type" : "requestGetGraphs", "space" : "config", "v" : 1.1, "id" : "dsaf" }`);
graph-request.json:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id" : "graph-requests.json",
"definitions": {
"requestGraph" : {
"$id" : "#/definitions/requestGraph",
"allOf" : [
{ "$ref" : "call.json/#/definitions/request" },
{
"properties": {
"space": {
"$id" : "#requestGraph/properties/space",
"type": "string",
"const": "config"
}
}
}
]
}
},
"requestGetGraphs" : {
"$id" : "requestGetGraphs",
"type" : "object",
"allOf" : [
{
"properties": {
"action": {
"$id" : "#requestGetGraphs/properties/action",
"type": "string",
"const": "requestGetGraphs"
}
}
},
{ "$ref" : "#/definitions/requestGraph" }
]
}
}