I wrote a schema in JavaScript because its easier, which I can simply run to turn it into JSON.
That part is all fine, but now I want to extract a sub-schema/definition because the application I want to use it with won't let me specify a JSON path for the sub-schema I'm interested.
So I tried writing a little script to pull it out:
#!/usr/bin/env node
import Ajv from 'ajv';
import Path from 'path';
const ajv = new Ajv({
$data: true,
});
ajv.addSchema(require(Path.resolve(process.argv[2])).default,'x');
const schema = ajv.getSchema(`x#/${process.argv[3]}`).schema;
console.log(JSON.stringify(schema,null,4));
But what I get back is:
{
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"$ref": "#/defs/Identifier"
},
"versions": {
"type": "array",
"items": {
"$ref": "#/defs/TableVersion"
}
}
},
"required": [
"name",
"versions"
]
}
i.e., I lost the other definitions!
Are there some API methods in AJV to pull out a sub-schema without breaking all the $refs?