Swashbuckle / Swagger Codegen IO:不带OperationId的更改服务命名约定

时间:2020-07-30 05:46:35

标签: .net angular swagger swashbuckle swagger-codegen

我们正在使用Swagger IO CodeGen,以获取C#Net Core 3 API,并自动生成Angular API服务代理。

https://editor.swagger.io/

此代码行根据API方法名称(Get,Put,Post)创建OperationId。操作ID,链接到Swagger IO并专门命名,并且等于Angular代理方法。

return services.AddSwaggerGen(c =>
{
    c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["action"]}");

Swagger Codegen IO: Change Service Naming Convention and Nickname

目标是:我们希望代理类等于控制器,代理方法等于控制器方法。 但是,使用操作ID,一切都必须是唯一的。因此,这会导致多个Gets,Posts,Get All等问题

问题是,我们如何才能避免此问题,或者Swagger IO除了operationId之外还可以利用其他资源?

网络核心:

public class ProductController : BaseApiController
{
    public async Task<ActionResult<ProductResponse>> GetAll()

public class CustomerController : BaseApiController
{
    public async Task<ActionResult<CustomerResponse>> GetAll()

public class AccountController : BaseApiController
{
    public async Task<ActionResult<AccountResponse>> GetAll()

角度打字稿:

export class ProductService {
    public getAll(

export class CustomerService{
    public getAll(

export class AccountService{
    public getAll(

但是它给出了语义错误

路径上的语义错误。/api/Product.getAll操作必须具有唯一的operationId。

enter image description here

0 个答案:

没有答案
相关问题