c# - Swagger Codegen IO:更改服务命名约定和昵称
问题描述
在创建 Angular API 服务代理时,是否有覆盖 Swagger IO CodeGen 命名约定的方法?
它的命名是这样的:API + 控制器名称 + 控制器方法 + 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
是用于标识操作的可选唯一字符串。如果提供,这些 ID 在您的 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,您可以通过以下几种不同的方式指定 operationId:
[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"'
另请参阅
推荐阅读
- rust - 如何简化重复功能逻辑
- javascript - 使用 Reactstrap 从 API 填充下拉列表
- firebase - Firebase 的 GA | 在漏斗的哪一步使用“present_offer”事件
- javascript - 如何通过单击html表格中的按钮来设置类
- reactjs - React-Typescript:JSX 元素类型“组件”没有任何构造或调用签名
- swift - 在 SwiftUI RealityKit 应用中加载 DAE 文件
- javascript - 固定每行的元素编号
- java - 生成没有开放 2x2 房间/空间的迷宫
- python - 一页上的多个表单Django
- java - 如何忽略非整数输入并继续输入