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

feat(swagger): Provide URI version to operationIdFactory #2549

Merged

Conversation

deongroenewald
Copy link
Contributor

This is based on the work completed in #1949. Those changes were reverted due to test failures.
This change adapts those changes to also support neutral versions which resolves the test failures.

Adds a new optional parameter to operationIdFactory to allow providing the API version prefix added to the operation's path.

This allows the operationIdFactory to generate unique IDs in the case of the same controller method being used for multiple API versions.

Default behavior is unchanged - the operation IDs will be of the form controllerKey_methodKey, but where necessary this can be customised using the URI version prefix.

Closes #2537

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

When using Nest's API versioning feature, and having a controller method cover multiple versions, nestjs-swagger generates invalid OpenAPI spec, due to duplicate operation IDs.

It generates duplicate operation IDs because only the controller and method names are available to `operationIdFactory - but in these cases the same controller and method is used multiple times.

Issue Number: 2537

What is the new behavior?

When URI versioning is used, an additional parameter containing the version is provided to operationIdFactory. This allows developers to provide unique operation IDs in the case of a method being used in multiple versions.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Adds a new optional parameter to operationIdFactory to allow providing the API version prefix added to the operation's path.

This allows the operationIdFactory to generate unique IDs in the case of the same controller method being used for multiple API versions.

Default behavior is unchanged - the operation IDs will be of the form controllerKey_methodKey, but where necessary this can be customised using the URI version prefix.

This is based on the work completed in nestjs#1949. Those changes were reverted due to test failures.

This change adapts those changes to also support neutral versions which resolves the test failures.

Closes nestjs#2537
@kamilmysliwiec kamilmysliwiec merged commit 062dcb6 into nestjs:master Aug 7, 2023
1 check passed
@kamilmysliwiec
Copy link
Member

LGTM

@deongroenewald deongroenewald deleted the operation-ids-with-version branch August 14, 2023 14:58
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.

Duplicate operationId's for routes supporting multiple versions
2 participants