简体   繁体   中英

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?

https://editor.swagger.io/

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.

Currently linking Net Core 3 APIs with Angular Typescript.

Will accept javascript answer for CodeGen.

Update Possible Solution:

How do I change the nickname property in C#?

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.

"nickname": "addPet",

You are looking for the operationId property:

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/

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:

[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).

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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