question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default x-operation-name To Controller Method Name

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently the generated operationId in the OpenAPI spec follows this pattern: <Controller Class Name>_<Controller Class Method Name>.

This in itself is probably a good thing. But then when I use ng-openapi-gen it will generate a method from the exact operationId.

So for my findAll() GET method of my CatsController class it will generate me an Angular service with the following method name: catsControllerFindAll().

Expected behavior

The current behavior is undesirable because the catsControllerFindAll() method belongs to my CatsApiService. So it would be much better if findAll() method would be generated in my CatsApiService

Fortunately ng-openapi-gen can support this using the x-operation-name tag. See here about the x-operation-name tag

So what I am asking is the following:

  • By default, set the x-operation-name tag to be just the name of the method. So for my findAll() GET method of my CatsController, the x-operation-name tag would have a value of findAll.
  • Add xOperationName to the options object of the @ApiOperation() decorator. And if the xOperationName is specified, then set the x-operation-name tag to the value specified.

What is the motivation / use case for changing the behavior?

I kind of already explained the motivation with my previous example. The motivation is to make the generated API services in Angular spit out more friendly method names.

Environment


Nest version: 6.14.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
aleix10kstcommented, Mar 21, 2021

I’ve seen this has been fixed here: #747

1reaction
kamilmysliwieccommented, Apr 17, 2020

We can make this configurable. Would you like to create a PR for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

how controller and action name other than default one Home ...
Here Home/Index sets as default one along with Url place holders for controller/action/id. I understand, when someone hit the browser with url ( ......
Read more >
Routing to controller actions in ASP.NET Core - Microsoft Learn
MapControllerRoute(name : "default", pattern: "{controller=Home}/{action=Index}/{id?}"); The route names give the route a logical name. The named ...
Read more >
Custom Method Names in Web API - Dot Net Tutorials
In this article, I am going to discuss How to create Custom Method Names in Web API. Why do we need to create...
Read more >
Action method in ASP.NET MVC - TutorialsTeacher
Every controller can have a default action method as per the configured route in the RouteConfig class. By default, the Index() method is...
Read more >
Controllers - Laravel - The PHP Framework For Web Artisans
When registering routes for single action controllers, you do not need to specify a controller method. Instead, you may simply pass the name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found