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

$patch remove keyword from required #40

Open mostafahatem20 opened 3 years ago

mostafahatem20 commented 3 years ago

I saw in the tests how to add an attribute to the required keyword { "op": "add", "path": "/required/-", "value": "q" } but I want to ask how can i remove a keyword from being required I tried { "op": "remove", "path": "/required/-q"} but it did not work i seem to get it wrong so if anyone can help I would be grateful. Thank you

pieterjandesmedt commented 3 years ago

Value-based array operations are not supported yet in JSON patch. See this issue: https://github.com/json-patch/json-patch2/issues/18 You need to remove values in an array based on index.

An example target JSON document:

   { "foo": [ "bar", "qux", "baz" ] }

A JSON Patch document:

   [
     { "op": "remove", "path": "/foo/1" }
   ]

The resulting JSON document:

   { "foo": [ "bar", "baz" ] }