Fix invalid implementation of nullable enum #1562
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What and why?
tsoa currently does not correctly implement OpenAPI v3+ enums when they are marked as nullable. According to the official documentation: https://swagger.io/docs/specification/data-models/enums/
A nullable enum can be defined as follows:
Note that null must be explicitly included in the list of enum values. Using nullable: true alone is not enough here.
This PR aims to fix this issue, so that tsoa more closely matches the specifications. This should fix e.g. an issue where
openapi-typescript
would not mark a field as nullable, becausenull
is missing from the enum list.All Submissions:
If this is a new feature submission:
I made this change mostly motivated by our own goals in using tsoa along with
openapi-typescript
in our product, and this was a pain point I encountered during my implementation, soo I thought I'd take a shot at fixing it.Potential Problems With The Approach
Backwards-compatibility? Edge cases?
I don't know if the way I implemented this "fix" is correct, but it seems to work, and nothing else broke. My understanding of the tsoa codebase is still in the "wtf am I doing" range.
Test plan
Confirms that
null
is added to the OpenAPI enum field if nullable is also present, to match expected behavior from specifications.