mokkabonna / json-schema-merge-allof

Simplify your schema by combining allOf
97 stars 23 forks source link

Merging compatible Integers and Numbers #42

Open GlennButera opened 1 year ago

GlennButera commented 1 year ago

Integer and Number JSON Schemas are immediately marked as incompatible without inspecting the other keywords in the schema. If a JSON Schema is of "type": "number" and has a "multipleOf" keyword value that is an integer, then it can be merged with a JSON Schema of "type": "integer" and should maintain the "multipleOf" keyword. For example:

{
  "type": "object",
  "properties": {
    "num": {
      "allOf": [
        {
          "type": "integer",
          "minimum": 1,
          "maximum": 12
        },
        {
          "type": "number",
          "minimum": 2,
          "maximum": 42,
          "multipleOf": 2
        }
      ]
    }
  }
};

can be merged into:

{
  "type": "object",
  "properties": {
    "num": {
      "type": "integer",
      "minimum": 2,
      "maximum": 12,
      "multipleOf": 2
    }
  }
};