-
Notifications
You must be signed in to change notification settings - Fork 494
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
Default Operation ID clashes #482
Comments
Currently using this as a bandaid fix after the json doc compiles, it overrides all regardless since I'm not doing any smart checking for duplicates: Object.entries(document.paths).forEach(([path, obj]) => {
['get', 'patch', 'put', 'post', 'delete'].forEach(method => {
if (obj[method]) {
obj[method].operationId = `${path.split('/')[1]}__${obj[method].operationId}`;
}
});
}); |
Fixed in 4.1.14 |
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 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, #487 is clearly a breaking change, have to update all projects that are using our generated api clients! |
I totally aggre with @maxfriedmann. It is a breaking change, i have to downgrade. Existed client API calls are all invalid now. |
I agree with @maxfriedmann. It is a breaking change and now I have to update 100 of backend calls in my client. This should either have an option to disable it or be reversed completely. I have to downgrade too. |
@kamilmysliwiec, am too far away from @nestjs/swagger development, do you think there could be an easy option to disable this behavior? |
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 type SwaggerOperationIdStrategy =
| 'FUNCTION_NAME' // old behaviour
| 'CONTROLLER_FUNCTION_NAME' // default, current behaviour
| (instance: object, method: Function) => string // custom behaviour, make your own Id
new DocumentBuilder()
.setTitle('Cats example')
.setDefaultOperationIdStrategy('FUNCTION_NAME') |
Had the same issue with my Angular client libraries after updating to >= 4.1.14. Just provided a PR to make this behavior configurable: #747 |
I'm submitting a...
Current behavior
Two controllers with the same operation will produce the same operation ID if no ID is provided when using tsc to compile.
Expected behavior
Take the name of the controller also, or append a hash
Minimal reproduction of the problem with instructions
@ApiOperation()
decorator, do not provide anoperationId
nest build
command works)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:
The text was updated successfully, but these errors were encountered: