【发布时间】:2020-11-18 12:17:38
【问题描述】:
在为现有的 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"'
有没有办法在启动时循环遍历所有控制器和方法?名称应与控制器中的操作方法的名称相同。
这也许是可能的解决方案,但是,我需要行动值。
return services.AddSwaggerGen(c =>
{
c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["controller"]}_{e.HttpMethod}");
【问题讨论】:
-
我认为如果你想生活在冒险的一边,从技术上讲,你可以用
Name = "[controller]_[action]"进行巨大的搜索/替换,这将假设[Http(...)]属性已经存在
标签: c# .net asp.net-core swagger swashbuckle