You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Routes that support multiple versions, either by specifying the versions on the controller or the routes themselves, result in duplicate operationId's in the same specification.
Breaking the requirement for operationId's to be unique amongst all operations causes some tools, like code generation, to fail.
The SwaggerModule.createDocument() function does support passing in an operationIdFactory function to customise the generated operationId's and I was hoping it would offer a simple option to workaround the problem.
However, the function is called multiple times with the same controllerKey and methodKey and isn't really provided with enough information about the route/version so would have to do some additional book-keeping of its own to try an generate a unique ID each time which isn't ideal.
The OpenAPI specification states that the operationId MUST be unique among all operations:
Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.
Automatically generated operationIds should be guaranteed to be unique
operationIdFactory methods should be provided with enough information to distinguish between what version of the route the operationId is being generated for.
Package version
7.1.2
NestJS version
10.0.0
Node.js version
v18.14.1
In which operating systems have you tested?
macOS
Windows
Linux
Other
No response
The text was updated successfully, but these errors were encountered:
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.
Closesnestjs#2537
Is there an existing issue for this?
Current behavior
Routes that support multiple versions, either by specifying the versions on the controller or the routes themselves, result in duplicate
operationId
's in the same specification.Breaking the requirement for
operationId
's to be unique amongst all operations causes some tools, like code generation, to fail.The
SwaggerModule.createDocument()
function does support passing in anoperationIdFactory
function to customise the generatedoperationId
's and I was hoping it would offer a simple option to workaround the problem.However, the function is called multiple times with the same
controllerKey
andmethodKey
and isn't really provided with enough information about the route/version so would have to do some additional book-keeping of its own to try an generate a unique ID each time which isn't ideal.Minimum reproduction code
https://github.com/deongroenewald/nestjs-multiversion-duplicate-operation-id
Steps to reproduce
npm start
http://localhost:3000/api-json
operationId
:AppController_getHello
Expected behavior
The OpenAPI specification states that the
operationId
MUST be unique among all operations:operationId
s should be guaranteed to be uniqueoperationIdFactory
methods should be provided with enough information to distinguish between what version of the route theoperationId
is being generated for.Package version
7.1.2
NestJS version
10.0.0
Node.js version
v18.14.1
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: