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

前端 未结 5 1889
囚心锁ツ
囚心锁ツ 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:19

    Version 5 of Swashbuckle supports the following option (to be used in the call to AddSwaggerGen()):

    options.TagActionsBy(api => new[] { api.GroupName });
    

    This should be used in combination with the following attribute on your controllers or actions:

    [ApiExplorerSettings(GroupName = "...")]
    

    However, by default the group name is used to include the operation in a specific document. So this may lead to unexpected results (depends on your naming of the document in calls to options.SwaggerDoc(name, ...)).

    To make it work you may have to add this:

    options.DocInclusionPredicate((name, api) => true);
    

    Here, for every operation, name is the name of a document and the group name is available in api.GroupName. To include the operation in the document regardless of its group name, simply return true.

提交回复
热议问题