type: string
nullable: true # <---
enum:
- asc
- desc
- null # <--- without quotes, i.e. null not "null"
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, because null is missing from the enum list.
All Submissions:
[x] Have you followed the guidelines in our Contributing document?
[x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?
[x] Have you written unit tests?
[x] Have you written unit tests that cover the negative cases (i.e.: if bad data is submitted, does the library respond properly)?
[ ] This PR is associated with an existing issue?
If this is a new feature submission:
[ ] Has the issue had a maintainer respond to the issue and clarify that the feature is something that aligns with the goals and philosophy of the project?
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.
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.