gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:05:46 24 4
gpt4 key购买 nike

在为现有的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com