0

I search a tool which permit to generate JSONPatch from two JSONSchema. Example:

JSONSchema A:

{
  "$id": "https://example.com/person.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    },
    "age": {
      "description": "Age in years which must be equal to or greater than zero.",
      "type": "integer",
      "minimum": 0
    }
  }
}

Where JSON object can be:

{"firstName": "John", "lastName": "Doe", "age": 42 }

JSONSchema B (without age):

{
  "$id": "https://example.com/person.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    }
  }
}

Generated JSONPatch should be:

[
  { "op": "remove", "path": "/age" }
]

To obtain after apply patch, object:

{"firstName": "John", "lastName": "Doe" }

There are some tools for that ?

NB: I can find some tools like this or this but these generate JSONPatch from objects not from JSONSchemas.

Relequestual
  • 11,631
  • 6
  • 47
  • 83
bux
  • 7,087
  • 11
  • 45
  • 86
  • JSON Schema is JSON. Why do you believe that what will work for JSON will not work for "A JSON Schema"? – Relequestual Nov 25 '19 at 15:31
  • Because the JSONPatch generated from these two JSONSchema will not permit patching objects matching with first JSONSchema. Current "pure JSON" JSONPatch generated from these two JSONSchema is `[{ "op": "remove", "path": "/properties/age" }]` not `[{ "op": "remove", "path": "/age" }]`. – bux Nov 25 '19 at 15:38
  • In which case, I think you're very unlikely to see such tooling. JSON Schema is very much more complex than just a field or not existing. Your best bet would be to make some tooling which, for simple cases, can transform the transform from two schemas. – Relequestual Nov 25 '19 at 15:51
  • Ok, thanks for this remark. – bux Nov 25 '19 at 16:08

0 Answers0