Net Core: Swashbuckle Set operationId Automatically on to Controller Action Method

喜你入骨 提交于 2020-08-10 03:37:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!