I've started using JSON schema in a project and it's all working well until I've tried using merge patch. There doesn't seem to be too many examples out there regarding merge/patch for cases where the schema being modified has references inside it so I was hoping I could get some guidance. I have a test schema:
const Ajv = require("ajv")
const ajv = new Ajv({allErrors: true, v5: true})
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
require('ajv-merge-patch')(ajv);
console.log("Start with base schema ================================")
const a = {
"$id": "a.json#",
type: "object",
properties: {
size: {type: "number"}
},
required: ["size"],
additionalProperties: false
}
ajv.addSchema(a, "a.json")
I believe this is due to refs not being replaced in the schema. Firstly I was wondering if what I am doing is odd or not - the main reason I was doing it this way is because in my actual scenario I have multiple properties based off of the same schema but only want to merge additional properties into some of them.
If it's not odd then how would I get the above to work?
Hi,
I've started using JSON schema in a project and it's all working well until I've tried using merge patch. There doesn't seem to be too many examples out there regarding merge/patch for cases where the schema being modified has references inside it so I was hoping I could get some guidance. I have a test schema:
A simple merge works okay
however, if I create a schema with a reference to the first one inside and try to extend the inner schema via the outer schema it fails:
I believe this is due to refs not being replaced in the schema. Firstly I was wondering if what I am doing is odd or not - the main reason I was doing it this way is because in my actual scenario I have multiple properties based off of the same schema but only want to merge additional properties into some of them.
If it's not odd then how would I get the above to work?
Many thanks