ajv-validator / ajv-merge-patch

$merge and $patch keywords for Ajv JSON-Schema validator to extend schemas
https://ajv.js.org
MIT License
46 stars 17 forks source link

Merge schemas with required properties #31

Closed tomasgvivo closed 5 years ago

tomasgvivo commented 5 years ago

Given schema1

{
  type: 'object',
  properties: {
     properties: {
        foo: { type: "string" }
      },
  },
  required: ["foo"]
}

And given schema2

{
  $merge: {
    source: schema1,
    with: {
      type: 'object',
      properties: {
        bar: { type: "string" }
      },
      required: ["baz"]
    }
  }
}

I expect foo and bar to be required in schema2. Instead, only bar is required.

Is this a bug or a feature?

epoberezkin commented 5 years ago

$merge does merging as defined in the related RFC (see the docs) - array values are supposed to be overwritten. $patch allows adding to arrays but with more complex syntax.