I understand that the typical response to this is to use
"type":"["string", "null"]
But the OpenAPI version we have is 3.0.x, not 3.1 so the type of null is not available. I am trying to find a way to get our JSON to validate a field that can be either a string OR null
Current field is
"type":"string",
"pattern": "...actual pattern is kind of long...",
"example": "2018-08-28",
"description": "Description of the field here.",
"nullable":true,
But this doe snot validate a null entry as valid. If I set
"type": ["string","null"],
It does validate it correctly, however this displays funky when compile the swagger docs so I am trying to find a way to allow a string or null, validate it AND get it to display correctly. With the above it displays all as one word stringnull for the type in the docs.
I have tried with JSON schema versions
- https://json-schema.org/draft/2020-12/schema
- "http://json-schema.org/draft-07/schema#"
OpenAPI version 3.0.1
OAS 3.0.x has a
nullableproperty they have defined for this purposeWhich validator are you using? It may not have implemented this keyword which is why you're having trouble using it.
You can validate it works with hyperjump-io
swap out the
dataanddata2to try the different instances.it shows up correctly on Swagger-UI free version.