在创建 Angular API 服务代理时,是否可以覆盖 Swagger IO CodeGen 命名约定?
其命名方式为: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/