So I have 2 JSONs (simplified for easy understanding):
{
"$schema":"https://json-schema.org/draft/2020-12/schema",
"$id":"header.scm",
"type":"object",
"additionalProperties":false,
"properties":{
"id":{
"type":"string",
"pattern":"^[A-Z]*([0-9]{17})$"
},
"verb":{
"type":"string",
"enum":[
"POST",
"GET",
"PUT",
"PATCH",
"DELETE"
]
}
},
"required":[
"id",
"endpoint"
]
}
{
"$schema":"https://json-schema.org/draft/2020-12/schema",
"$id":"wms_mission.scm",
"type":"object",
"properties":{
"header":{
"$ref":"#C:/schemas/header.scm"
},
"body":{
"additionalProperties":false,
"type":"object",
"properties":{
"mission_id":{
"type":"string",
"pattern":"^(MISSION)([0-9]{17})$"
},
"command":{
"type":"string",
"enum":[
"CREATE",
"CANCEL"
]
}
},
"required":[
"mission_id",
"command"
]
}
},
"required":[
"header",
"body"
],
"additionalProperties":false
}
This configuration of schemas checks that the messages that are sent have a header and a body and both of those have the correct configuration.
An example:
{
"body":{
"mission_id":"EJ_1",
"command":"CREATE",
},
"header":{
"id":"EXAMPLE_ID001",
"verb":"POST"
}
}
The thing is that the header is the same for all type of messages so I wanted to reference it.
As you can see, the second one checks the header configuration in the other file using an absolute path.
However, when I try to validate the schema I get this error message:
Check that the format follows the schema (wms_mission.scm). [header: is missing but it is required, body: is missing but it is required]
I don’t really understand what I’m doing wrong.
I tried playing with the relative path but I only got exceptions or it give it back as “correct”.
Any idea of how to reference another JSON schema file from a JSON schema?
Thanks in advance!
Danielps1818 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.