[英]How to add hyphen in class title of swagger.json
I am using Asp .net core 3.1.我正在使用 Asp .net 核心 3.1。 I want to update the controller name in swagger.json of Swashbuckler.AspNetCore which is a auto generated file.我想更新 Swashbuckler.AspNetCore 的 swagger.json 中的 controller 名称,这是一个自动生成的文件。 for Example class title as School-Admin例如 class 标题为 School-Admin
I am using RestFul APIs, In Restful APIs, we use hyphen separated entities name For example我正在使用 RestFul API,在 Restful API 中,我们使用连字符分隔的实体名称 例如
Controller School-Admin
[GET] api/school-admins/1
As c# doest not allow hyphen in class name so I can't change my controller name..I want to achieve this usinh swagger..json As c# doest not allow hyphen in class name so I can't change my controller name..I want to achieve this usinh swagger..json
To achieve this I have added a hyphen in [Route("api/school-admins")] Right now, It works for Endpoints only and doest not add hyphen in class title.为了实现这一点,我现在在 [Route("api/school-admins")] 中添加了一个连字符,它仅适用于端点,并且不在 class 标题中添加连字符。 it shows the API and class name on swagger UI as:它在 swagger UI 上显示 API 和 class 名称:
SchoolAdmin => Class Title not hyphen separated on swagger UI yet
GET api/school-admins/{id} => API
My goal is to display class name hyphen separated on swagger UI since swash buckle creates swagger.json automatically so it adds the class name same as mentioned in.cs file which is not hyphen separated due to language restrictions. My goal is to display class name hyphen separated on swagger UI since swash buckle creates swagger.json automatically so it adds the class name same as mentioned in.cs file which is not hyphen separated due to language restrictions. is it possible to change my class title in swagger.json without affecting auto generated functionality?是否可以在 swagger.json 中更改我的 class 标题而不影响自动生成的功能? I am using Swashbuckle.AspNetCore in which swagger.json generates automatically and also that file is non editable.我正在使用 Swashbuckle.AspNetCore,其中 swagger.json 会自动生成,并且该文件也是不可编辑的。 Can I change the class name in this auto-generated swagger.json and push it into source control but it should not affect my auto-generated functionality of swagger.json.For example, if I add a new API or controller in the future swagger.json should be auto-updated with new changes only Dev need to add new class name hyphen separated if required. Can I change the class name in this auto-generated swagger.json and push it into source control but it should not affect my auto-generated functionality of swagger.json.For example, if I add a new API or controller in the future swagger .json 应该自动更新,只有开发人员需要添加新的 class 名称连字符分隔如果需要。
Posting to help other I solved it using APIExplorerSettings I was unaware of that before.发布以帮助其他人我使用 APIExplorerSettings 解决了它,我以前不知道这一点。 In startup.cs I use在 startup.cs 我使用
SwaggerGen(){
options.DocInclusionPredicate((_, api) => !string.IsNullOrWhiteSpace(api.GroupName));
options.TagActionsBy(api => new[] { api.GroupName });}
in Classes在类
[ApiExplorerSettings(GroupName = "school-admin")]
and see the magic看看魔法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.