c# - 网络核心 : Swashbuckle Set operationId Automatically on to Controller Action Method

标签 c# .net asp.net-core swagger swashbuckle

在为现有的 500 多个 Controller 和相应方法创建 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 和方法?名称应等于 Controller 中操作方法的名称。

这可能是可行的解决方案,但是,我需要操作值。

return services.AddSwaggerGen(c =>
{
    c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["controller"]}_{e.HttpMethod}");

https://stackoverflow.com/a/54294810/13889515

最佳答案

利用这段代码:

return services.AddSwaggerGen(c =>
{
    c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["action"]}");

关于c# - 网络核心 : Swashbuckle Set operationId Automatically on to Controller Action Method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63144598/

相关文章:

c# - C# 中带附件的 SOAP (SwA)

c# - * 运算符必须应用于代码中的指针错误

c# - "Tool tip"是否被 ToolStripItems 覆盖(如果它们有下拉项)?

asp.net-core - 如何在 ASP.NET Core 中处理 PROPFIND HTTP Verb 请求(或其他)?

iis - ASP.NET Core 无法在 IIS 下运行 : HTTP Error 500. 0 - ANCM In-Process Handler Load Failure

c# - 从 Azure WebJob 运行 Python 脚本

c# - 如何防止弹出表单从父级获取焦点

c# - 避免 LINQ to SQL 中的 2100 个参数限制

c# - 将图像列表绑定(bind)到 ListBox

asp.net-core - 在 Entity Framework Core 3.1 中使用 DateTime 作为 SQL 时间列