Closed jwilmoth-nc closed 10 months ago
Hey Jon,
first thing is you are using Draft-07 JSON schema. Shale supports only Draft 2020-12. Second thing is $refs in JSON schema are not paths, they are just identifiers used to resolve references. You have to provide all the schema files that you're using.
Taken from https://json-schema.org/understanding-json-schema/structuring.html#id
Even though schemas are identified by URIs, those identifiers are not necessarily network-addressable. They are just identifiers. Generally, implementations don’t make HTTP requests (https://) or read from the file system (file://) to fetch schemas. Instead, they provide a way to load schemas into an internal schema database. When a schema is referenced by it’s URI identifier, the schema is retrieved from the internal schema database.
So working example would look like this:
shaleb -c -i user.json,common.json
And schema files:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://example.com/schemas/user.json",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"address": {
"$ref": "http://example.com/schemas/common.json#/$defs/address"
}
}
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://example.com/schemas/common.json",
"$defs": {
"address": {
"type": "object",
"properties": {
"street": {
"type": "string"
},
"city": {
"type": "string"
}
}
}
}
}
https://www.shalerb.org/#compiling-json-and-xml-schema uses a simple example for generation that doesn't include $refs. Given a file that uses a simple relative path ref that exists in the same directory, the
shaleb -c -i user.json
command fails with the following message:cat user.json| jq
cat common.json| jq