opis / json-schema

JSON Schema validator for PHP
https://opis.io/json-schema
Apache License 2.0
567 stars 58 forks source link

fix: Allow enum with type null #125

Closed MathieM closed 1 month ago

MathieM commented 1 year ago

Enum with both type with null, and string thow a validation error.

{
    "type": ["string", null],
    "enum": ["A", "B"]
}

Today we need to use

{
  "oneOf": {
      [
          {
              "type": null
          },
          {
              "type": "string",
              "enum": ["A", "B"]
          }
      ]
  }
}

or

{
    "type": ["string", null],
    "enum": [null, "A", "B"]
}
sorinsarca commented 1 month ago

https://opis.io/json-schema/2.x/null.html

You should use the name of the type as string

{
  "type": ["string", "null"]
}