Default Operation ID clashes
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Two controllers with the same operation will produce the same operation ID if no ID is provided when using tsc to compile.
@Controller('a')
class A {
@ApiOperation()
getOne(){...}
}
@Controller('b')
class B {
@ApiOperation()
getOne(){...}
}
// Output truncated
{
"paths" : {
"a" : {"get" : {"operationId": "getOne"}},
"b" : {"get" : {"operationId": "getOne"}},
}
}
Expected behavior
Take the name of the controller also, or append a hash
// Output truncated
{
"paths" : {
"a" : {"get" : {"operationId": "a__getOne"}},
"b" : {"get" : {"operationId": "b__getOne"}},
// or
"a" : {"get" : {"operationId": "getOne_r@nd0mH4$h"}},
"b" : {"get" : {"operationId": "getOne_abcd12345"}},
}
}
Minimal reproduction of the problem with instructions
- Create two controllers with the same name for a method
- Expose the same named method with
@ApiOperation()
decorator, do not provide anoperationId
- Use TSC to compile (untested if
nest build
command works) - View the JSON output
What is the motivation / use case for changing the behavior?
This is causing issues where operationId fields are expected to be globally unique but the value of them isn’t important. I am using the JSON output in an OpenAPI UI generator called redoc. Without the unique operationIds, the links it produces are broken because all links with the same name point to the same endpoint, and this is frequent for my project as I’m using generic controllers.
Environment
Nest version: 6.10.14
For Tooling issues:
- Node version: 11.15
- Platform: Mac
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How to customize the value of operationId generated in api ...
This operationId is used while generating clients using swagger-codegen. Does anyone know how to customize it? I know this can be done per...
Read more >Handling Concurrency Conflicts - EF Core - Microsoft Learn
Managing conflicts when the same data is updated concurrently with Entity Framework Core.
Read more >OpenAPI Specification - Version 3.0.3 - Swagger
Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is...
Read more >Conflict Detection and Sync - AWS AppSync
Conflict Detection, Conflict Resolution, and Sync operations require a Versioned data ... and an ID of 1a and version of 2 , this...
Read more >Resolving HA cluster chassis ID conflicts
Once both FortiGates are operating in HA mode with different chassis IDs, they will negotiate to form a cluster, and if their chassis...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looking at the patch, I feel like this could be customisable behaviour if it were exposed in the settings.
https://github.com/nestjs/swagger/pull/487/files#diff-bb845d0d85e92f24987732c111594fb0R208 is how it decides what the default operation id is if there wasn’t one.
I envision something like
Just upgraded to the latest version and now my method names are unnecessary long when I use e.g. the open api generator. Before, it generated a nice
designService.updateImages
method based on the operationId, now it is calleddesignService.frontendDesignsControllerUpdateImages
?Is it possible to turn that off again and use the not-so-unique version? I understand that problem with doubled operationIds (been there, done that) but since you can easily work around that issue by scoping your swagger spec via nestjs modules, I’d really like to have the possibility to get back to the shorter method names…
So for me, https://github.com/nestjs/swagger/pull/487 is clearly a breaking change, have to update all projects that are using our generated api clients!