Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid implementation of nullable enum #1562

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

iffa
Copy link
Contributor

@iffa iffa commented Feb 15, 2024

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:

    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:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you written unit tests?
  • 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.

@WoH WoH merged commit a8a48eb into lukeautry:master Mar 12, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants