当我们为现有500多个控制器和相应方法创建Angular API服务代理时,我们正试图覆盖Swashbuckle / Swagger IO CodeGen命名约定。
当前将Net Core 3 API与Angular Typescript链接。
https://stackoverflow.com/a/58567622/13889515
以下答案有效:
[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"'
是否有一种方法可以在启动时循环遍历所有控制器和方法?名称应与Controller中动作方法的名称相同。
这可能是解决方案,但是,我需要操作值。
return services.AddSwaggerGen(c =>
{
c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["controller"]}_{e.HttpMethod}");
答案 0 :(得分:2)
利用这段代码:
return services.AddSwaggerGen(c =>
{
c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["action"]}");