Swagger Codegen IO:更改服务命名约定和昵称
Swagger Codegen IO: Change Service Naming Convention and Nickname
在创建 Angular API 服务代理时,是否可以覆盖 Swagger IO CodeGen 命名约定?
它的命名公式为:API + 控制器名称 + 控制器方法 + HTTP 操作。
public apiProductGetProductByProductIdGet(productNumber?: string, observe?: 'body', reportProgress?: boolean): Observable<ProductResponse>;
我们想要restructure/reorder我们公司的命名约定。
目前正在将 Net Core 3 API 与 Angular Typescript 链接。
将接受 javascript CodeGen 的答案。
更新可能的解决方案:
如何在 C# 中更改昵称 属性?
https://docs.swagger.io/spec.html
”昵称。操作的唯一标识,可由读取输出的工具使用,以便进一步和更轻松地操作。例如,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,您可以通过以下几种不同的方式指定 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"'
另见
您还可以使用标签更改生成的客户端 SDK 服务命名约定(如果您像我一样希望防止与客户端服务发生冲突)。
不是标记为user
,而是让客户端SDK生成服务名称为UserService
,您可以使用user-api
的标记,生成的库服务将被命名UserApiService
.
https://swagger.io/docs/specification/2-0/grouping-operations-with-tags/
在创建 Angular API 服务代理时,是否可以覆盖 Swagger IO CodeGen 命名约定?
它的命名公式为:API + 控制器名称 + 控制器方法 + HTTP 操作。
public apiProductGetProductByProductIdGet(productNumber?: string, observe?: 'body', reportProgress?: boolean): Observable<ProductResponse>;
我们想要restructure/reorder我们公司的命名约定。
目前正在将 Net Core 3 API 与 Angular Typescript 链接。
将接受 javascript CodeGen 的答案。
更新可能的解决方案:
如何在 C# 中更改昵称 属性?
https://docs.swagger.io/spec.html
”昵称。操作的唯一标识,可由读取输出的工具使用,以便进一步和更轻松地操作。例如,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,您可以通过以下几种不同的方式指定 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"'
另见
您还可以使用标签更改生成的客户端 SDK 服务命名约定(如果您像我一样希望防止与客户端服务发生冲突)。
不是标记为user
,而是让客户端SDK生成服务名称为UserService
,您可以使用user-api
的标记,生成的库服务将被命名UserApiService
.
https://swagger.io/docs/specification/2-0/grouping-operations-with-tags/