Swagger Codegen IO:更改服务命名约定和昵称 [英] Swagger Codegen IO: Change Service Naming Convention and Nickname

查看:64
本文介绍了Swagger Codegen IO:更改服务命名约定和昵称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there anyway to override Swagger IO CodeGen naming conventions, when its creating Angular API Service Proxies?

https://editor.swagger.io/

按以下等式命名:API +控制器名称+控制器方法+ HTTP操作.

Its naming by this equation: API + Controller Name + Controller Method + HTTP Action.

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

我们要为公司重新命名/命名惯例.

We want to restructure/reorder the naming convention for our company.

当前将Net Core 3 API与Angular Typescript链接.

Currently linking Net Core 3 APIs with Angular Typescript.

将接受CodeGen的javascript答案.

Will accept javascript answer for CodeGen.

更新可能的解决方案:

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

How do I change the nickname property in C#?

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

"昵称.该操作的唯一ID,工具可以使用该ID读取输出,以进一步简化操作.例如,Swagger-Codegen将使用昵称作为其生成的客户端中操作的方法名称.该值必须为字母数字,并且可以包含下划线.不允许使用空格字符.

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

"nickname": "addPet",

推荐答案

您正在寻找 operationId 属性:

operationId 是可选的唯一字符串,用于标识手术.如果提供,这些ID在所有操作中必须是唯一的在您的API中进行了说明.

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-操作/

示例:

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

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

另请参见

这篇关于Swagger Codegen IO:更改服务命名约定和昵称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆