Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have NSwag ignore a controller?

Tags:

c#

swagger

nswag

I used NSwag to generate a client for a single controller; 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.

I tried adding this attribute at the top of the controller but it is still being noted in the specification: [ApiExplorerSettings(IgnoreApi = true)]

My controller is implementing the standard Microsoft.AspNetCore.Mvc.Controller class.

like image 413
James B. Nall Avatar asked Apr 18 '17 19:04

James B. Nall


People also ask

What is NSwag used for?

The NSwag project provides tools to generate OpenAPI specifications from existing ASP.NET Web API controllers and client code from these OpenAPI specifications. The project combines the functionality of Swashbuckle (OpenAPI/Swagger generation) and AutoRest (client generation) in one toolchain.

What is JSON NSwag?

NSwag is a Swagger 2.0 API (OpenAPI) toolchain for . NET, Web API, TypeScript (jQuery, AngularJS, Angular 2+, Aurelia, KnockoutJS, and more) and other platforms, written in C#. The Swagger specification uses JSON and JSON Schema to describe a RESTful web API.


2 Answers

I think in the latest version,

[ApiExplorerSettings(IgnoreApi = true)]

is supported.

Otherwise you can add the SwaggerIgnoreAttribute OR OpenApiIgnoreAttribute attribute

[SwaggerIgnore]
[OpenApiIgnore]

Or manually select the controllers in NSwagStudio or in the middleware...

like image 80
Rico Suter Avatar answered Sep 17 '22 19:09

Rico Suter


Use [OpenApiIgnore]

(since [SwaggerIgnore] has been deprecated)

like image 23
Arieh Avatar answered Sep 21 '22 19:09

Arieh