问题
We are trying to override Swashbuckle/Swagger IO CodeGen naming conventions, when its creating Angular API Service Proxies, for existing 500+ controllers and the corresponding methods.
Currently linking Net Core 3 APIs with Angular Typescript.
https://stackoverflow.com/a/58567622/13889515
The following answer works:
[HttpGet("{id:int}", Name = nameof(GetProductById))]
public IActionResult GetProductById(int id) // operationId = "GetProductById"'
[HttpGet("{id:int}", Name = "GetProductById")]
public IActionResult GetProductById(int id) // operationId = "GetProductById"'
Is there a way to loop through all controllers and methods in startup? Name should equal name of Action Method within Controller.
This maybe possible solution, However, I need the action value.
return services.AddSwaggerGen(c =>
{
c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["controller"]}_{e.HttpMethod}");
https://stackoverflow.com/a/54294810/13889515
回答1:
Utilize this piece of code:
return services.AddSwaggerGen(c =>
{
c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["action"]}");
来源:https://stackoverflow.com/questions/63144598/net-core-swashbuckle-set-operationid-automatically-on-to-controller-action-meth