简体   繁体   English

是否可以让 NSwag 忽略控制器?

[英]Is it possible to have NSwag ignore a controller?

I used NSwag to generate a client for a single controller;我使用 NSwag 为单个控制器生成客户端; I needed it as its own separate client.我需要它作为它自己独立的客户端。 I would like for it to be ignored when the Swagger specification is generated in the future.我希望在将来生成 Swagger 规范时忽略它。

I tried adding this attribute at the top of the controller but it is still being noted in the specification: [ApiExplorerSettings(IgnoreApi = true)]我尝试在控制器顶部添加这个属性,但它仍然在规范中注明: [ApiExplorerSettings(IgnoreApi = true)]

My controller is implementing the standard Microsoft.AspNetCore.Mvc.Controller class.我的控制器正在实现标准的Microsoft.AspNetCore.Mvc.Controller类。

I think in the latest version,我认为在最新版本中,

[ApiExplorerSettings(IgnoreApi = true)]

is supported.支持。

Otherwise you can add the SwaggerIgnoreAttribute OR OpenApiIgnoreAttribute attribute否则,您可以添加SwaggerIgnoreAttributeOpenApiIgnoreAttribute属性

[SwaggerIgnore]
[OpenApiIgnore]

Or manually select the controllers in NSwagStudio or in the middleware...或者在 NSwagStudio 或中间件中手动选择控制器...

Use [OpenApiIgnore]使用[OpenApiIgnore]

(since [SwaggerIgnore] has been deprecated) (因为[SwaggerIgnore]已被弃用)

@Arieh 's answer worked for me. @Arieh 的回答对我有用。 I'd like to share more.我想分享更多。

  1. Install package NSwag.Annotations for DTO class, for my case which is in separated project, then use [OpenApiIgnore] decorate the property which should be ignored.为 DTO 类安装包NSwag.Annotations ,对于我在单独项目中的情况,然后使用[OpenApiIgnore]装饰应该忽略的属性。
  2. Install package NSwag.AspNetCore for the web project.为 web 项目安装包NSwag.AspNetCore

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在不使用 [JsonIgnore] 的情况下忽略 nswag 中的 model 属性? - Is it possible to ignore a model property in nswag without using [JsonIgnore]? NSwag 更改控制器说明 - NSwag change controller description 使用NSwag和C#对控制器名称或标签进行排序 - Sort on controller name or tag with NSwag and C# 是否可以仅针对一项操作忽略 ServiceFilter 控制器? - It's possible to ignore a ServiceFilter controller for one action only? 如何按控制器名称对 NSwag swagger.json 中的路径进行排序/排序 - How to order/sort paths in NSwag swagger.json by controller name 是否可以引用未在.nswag文件中定义的C#类? - Is it possible to reference a C# class that's not defined in a .nswag file? 是否可以更改NSwag生成的“示例值”部分的内容? - Is is possible to change the contents of the Example Value section generated by NSwag? 在MVC3中,是否可以在不同的区域中使用相同的控制器名称? - Is it possible, in MVC3, to have the same controller name in different areas? 是否可以让多个MVC路由指向同一个控制器/视图? - Is it possible to have multiple MVC routes point to the same controller/view? 数据未将视图移至控制器,我尝试了所有可能的解决方案 - Data not moving view to controller, I have tried with all possible solutions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM