Is there a way change the Controller's name in the swagger-ui page?

前端 未结 5 1871
囚心锁ツ
囚心锁ツ 2021-02-18 20:03

I\'m using Swashbuckle to enable the use of swagger and swagger-ui in my WebApi project.

In the following image you can see two of my controllers shown in the swagger-ui

5条回答
  •  别那么骄傲
    2021-02-18 20:16

    If one wants to do this at a Controller / Class level, the following is a very useful extract from here

    use the [ApiExplorerSettings(GroupName = "Group")] on your controllers

    Then in Startup

    services.AddSwaggerGen(options =>
    {
    options.SwaggerDoc(version,
        new Info
        {
            Title = name,
            Version = version
        }
    );
    
    options.DocInclusionPredicate((_, api) => !string.IsNullOrWhiteSpace(api.GroupName));
    
    options.TagActionsBy(api => api.GroupName);
    });
    

    Also note that

    5.0.0-beta of swashbuckle now includes an TagActionsBy overload that supports returning an array of tags. This should allow for the above customizations to be simplified

提交回复
热议问题