简体   繁体   English

如何在 swagger.json 的 class 标题中添加连字符

[英]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.

相关问题 Swagger 不生成 swagger.json - Swagger is not generating swagger.json C# 从 swagger.json 生成 class 作为构建的一部分 - C# make class from swagger.json as part of build 使用 Swashbuckle Aspnetcore 将 `host`、`basePath` 和 `schemes` 添加到 swagger.json - Add `host`, `basePath` and `schemes` to swagger.json using Swashbuckle Aspnetcore 显示 Swagger.json 但 UI 不显示 - Swagger.json is displayed but the UI not 如何修复 .net core 2.2 应用程序中未找到的 swagger.json - How to fix swagger.json not found in .net core 2.2 app 如何按控制器名称对 NSwag swagger.json 中的路径进行排序/排序 - How to order/sort paths in NSwag swagger.json by controller name 如何从 swagger.json 中删除反引号 - How to remove back quote from swagger.json .net core/swagger - 生成 swagger.json 文件时如何绕过控制器文件? - .net core/swagger - How can I around a controller file when generating the swagger.json file? 当本地主机提供 swagger.json 时,Autorest 无法针对文件解析 swagger.json - Autorest Failed resolving swagger.json against file when swagger.json is served by localhost 使用 GenerateSchema 添加的类出现在 Swagger UI 中,但不在 swagger.json 中 - Classes Added Using GenerateSchema Appear in the Swagger UI But Not in swagger.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM