-
Notifications
You must be signed in to change notification settings - Fork 488
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 #1949
feat(swagger): Provide URI version to operationIdFactory #1949
Conversation
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 nestjs#1711
bf46f02
to
fd11b46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good so far. What does it take to be merged?
Would love to have this feature too, what does it need to be merged? |
lgtm |
Hi everyone! Any update on this issue? It looks like it was merged, but accoring to the last comment the change was reverted because of the tests. Do you have any information about the delivery? Thanks in advance. |
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
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.
The implementation here gets the versions that the method is for, and generates the URI prefixes. It then looks for the version prefixes in the paths returned from
RoutePathFactory
, and provides that information to operationIdFactory, so that unique IDs can be generated.I'm not super familiar with Nest internals, but this looks like the only real way to implement this without making more extensive changes to
nest-router
, which would have potentially wider side effects.Closes #1711
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: #1711
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