c# - Swagger 代码生成 IO : Change Service Naming Convention and Nickname

标签 c# .net angular typescript swagger-codegen

在创建 Angular API 服务代理时,是否可以覆盖 Swagger IO CodeGen 命名约定?

https://editor.swagger.io/

其命名方式为:API + Controller 名称 + Controller 方法 + HTTP 操作。

public apiProductGetProductByProductIdGet(productNumber?: string, observe?: 'body', reportProgress?: boolean): Observable<ProductResponse>;

我们希望重组/重新排序我们公司的命名约定。

目前正在将 Net Core 3 API 与 Angular Typescript 链接起来。

将接受 CodeGen 的 javascript 答案。

更新可能的解决方案:

如何在 C# 中更改昵称属性?

https://docs.swagger.io/spec.html

“昵称。操作的唯一 ID,读取输出的工具可以使用它来进行进一步、更轻松的操作。例如,Swagger-Codegen 将使用昵称作为它生成的客户端中操作的方法名称。该值必须是字母数字,并且可以包含下划线。不允许使用空格字符。

"nickname": "addPet",

最佳答案

您正在查找 operationId 属性:

operationId is an optional unique string used to identify an operation. If provided, these IDs must be unique among all operations described in your API.

https://swagger.io/docs/specification/paths-and-operations/

示例:

/users:
  get:
    operationId: getUsers
    summary: Gets all users
    ...
  post:
    operationId: addUser
    summary: Adds a new user
    ...
/user/{id}:
  get:
    operationId: getUserById
    summary: Gets a user by user ID
    ...

如果您使用Swashbuckle ,您可以通过以下几种不同的方式指定操作Id:

[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"'

参见this还有

关于c# - Swagger 代码生成 IO : Change Service Naming Convention and Nickname,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63144012/

相关文章:

c# - 具有异步写入功能的自定义 NLog 目标

Angular 2。如何防止路线改变

c# - 使 C#.NET 中的 IntPtr 指向字符串值

javascript - Angular 7 测试 : NullInjectorError: No provider for ActivatedRoute

ios - 应用程序启动时的路由问题 Ionic 4

c# - 为什么我不能数据绑定(bind)到一个字段?

c# - SQL Server 中哪种方法更快?返回通过 DataTable 使用的 XML 数据或原始数据?

c# - MVC3路由表错误

c# - C# 中的空引用基本上是全零指针吗?

.net - 自定义线程在 Application_Start 中启动