Support null in OpenAPI 3.1 union types
Description
OpenAPI 3.1 dropped support for nullable. Instead, callers are expected to use array types:
# OpenAPI v3.0
type: string
nullable: true
# OpenAPI v3.1
type:
- "string"
- "null"
Reproduction
For a type like the one above, the generated type is OneOf<[string, Record<string, never>]>.
As far as I can tell, Record<string, never> is returned when the tool cannot tell what type it should be generating for.
Expected result
The generated type should be OneOf<[string, null]>
Checklist
- [X] My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint) - [X] I’m willing to open a PR (see CONTRIBUTING.md)
Actually it appears the quotes around "null" are necessary; it won't work without it.
Yes null is a valid YAML datatype, but not in JSON. It must be the literal string "null" as you described.
Your issue was still valid, though. The next release of 6.3.4 will improve the 3.1 nullable handling considerably.