Add linting rule to validate nullable enums
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 228
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 48
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the built-in linter rules and the custom-rule path for OpenAPI schemas. Add coverage for nullable enums with and without null, then confirm the non-conforming examples fail linting while conforming examples pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100