简体   繁体   English

Swagger Codegen IO:更改服务命名约定和昵称

[英]Swagger Codegen IO: Change Service Naming Convention and Nickname

Is there anyway to override Swagger IO CodeGen naming conventions, when its creating Angular API Service Proxies?在创建 Angular ZDB974238714CA38DE634A7CE10 时,是否有覆盖 Swagger IO CodeGen 命名约定?

https://editor.swagger.io/ https://editor.swagger.io/

Its naming by this equation: API + Controller Name + Controller Method + HTTP Action.其命名方式如下:API + Controller 名称 + Controller 方法 + Z293C9EA246FF9985DC6F62A650F78 动作。

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

We want to restructure/reorder the naming convention for our company.我们想为我们公司重组/重新排序命名约定。

Currently linking Net Core 3 APIs with Angular Typescript.目前将 Net Core 3 API 与 Angular Typescript 链接。

Will accept javascript answer for CodeGen.将接受 CodeGen 的 javascript 答案。

Update Possible Solution:更新可能的解决方案:

How do I change the nickname property in C#?如何更改 C# 中的昵称属性?

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

"Nickname. A unique id for the operation that can be used by tools reading the output for further and easier manipulation. For example, Swagger-Codegen will use the nickname as the method name of the operation in the client it generates. The value MUST be alphanumeric and may include underscores. Whitespace characters are not allowed. “昵称。操作的唯一 id,可以由读取 output 的工具使用,以便进一步和更轻松地操作。例如,Swagger-Codegen 将使用昵称作为它生成的客户端中操作的方法名称。该值必须是字母数字,可以包含下划线。不允许使用空白字符。

"nickname": "addPet",

You are looking for the operationId property:您正在寻找operationId属性:

operationId is an optional unique string used to identify an operation. operationId是用于标识操作的可选唯一字符串。 If provided, these IDs must be unique among all operations described in your API.如果提供,这些 ID 在 API 中描述的所有操作中必须是唯一的。

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

Example:例子:

/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
    ...

If you're using Swashbuckle , you can specify the operationId a couple of different ways below:如果您使用的是Swashbuckle ,您可以通过以下几种不同的方式指定 operationId:

[HttpGet("{id:int}", Name = nameof(GetProductById))]
public IActionResult GetProductById(int id) // operationId = "GetProductById"'

or或者

[HttpGet("{id:int}", Name = "GetProductById")]
public IActionResult GetProductById(int id) // operationId = "GetProductById"'

See this also参阅

You can also change the generated client SDK service naming conventions using tags (if you're like me and want to prevent conflict with client services).您还可以使用标签更改生成的客户端 SDK 服务命名约定(如果您像我一样并想防止与客户端服务发生冲突)。

Instead of tagging as user , and having the client SDK generate the service name as UserService , you can use the tag of user-api and the generated library service will be named UserApiService .您可以使用user-api的标签,而不是标记为user ,让客户端 SDK 生成服务名称为UserService ,生成的库服务将命名为UserApiService

https://swagger.io/docs/specification/2-0/grouping-operations-with-tags/ https://swagger.io/docs/specification/2-0/grouping-operations-with-tags/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM