feat(swagger): Provide URI version to operationIdFactory #2549
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.
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?
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?
Other information