redocly-cli
redocly-cli copied to clipboard
Add linting rule to validate nullable enums
Currently, the OpenAPI spec has this to say about nullable enums:

Despite running our API spec through the linter with a non-conforming nullable enum, it passed! The end result was that a consumer downstream was having trouble integrating because they could not generate a client from the spec
I think it would be a great benefit to add a rule that explicitly checks:
IF `type` is `enum` AND `nullable` is `true`: ensure null appears in the list of values
The temporary solution I was considering is a custom rule, but this feels like something that should come out of the box as a built-in rule
Here is an example of something that should not pass linting, but does:
myEnumType:
type: string
nullable: true
enum:
- "foo"
- "bar"
- "baz"
And this is what it should be in order to conform:
myEnumType:
type: string
nullable: true
enum:
- "foo"
- "bar"
- "baz"
- null
conversely, this should also fail:
myEnumType:
type: string
nullable: false
enum:
- "foo"
- "bar"
- "baz"
- null
Hi, thanks for reporting!
Could you specify the exact and OAS and Redocly CLI versions?
Of course! Sorry I should have included that originally
- OpenAPI version: 3.0.1
- Readocly CLI version: 1.0.0-beta.125