[英]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否则,您可以添加SwaggerIgnoreAttribute
或OpenApiIgnoreAttribute
属性
[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.我想分享更多。
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]
装饰应该忽略的属性。NSwag.AspNetCore
for the web project.为 web 项目安装包NSwag.AspNetCore
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.