RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.71k stars 1.24k forks source link

Is it possible to setup controllers and actions filtering? #3168

Open Oglan opened 3 years ago

Oglan commented 3 years ago

We use NSwag in our project. There are a lot of controllers and actions there. We'd like to let our front developers to find api methods faster by letting them to filter somehow controllers and actions. Does NSwag provide such functionality?

I found such option in Swashbuckle library, but don't want to change everything just for one feature :)

RicoSuter commented 3 years ago

You want to filter out operations in the spec -> register a custom operation processor and return false for the hidden ones

sascha-andres commented 3 years ago

Sorry to hijack this thread but I want to hide models from the generated document. I have found context.Settings.ExcludedTypeNames where the documentation says JsonSchemaIgnoreAttribute will do the same.

Somehow I do not get both methods working. I tried with an operations processor like this:

internal class SwaggerSchemaProcessor : ISchemaProcessor
{
  public void Process( SchemaProcessorContext context )
  {
    context.Settings.ExcludedTypeNames = new[] { "PM.Api.Data.BusinessUnit" };
  }
}

I registered it like this:

services.AddSwaggerDocument( document => {
                                 document.SchemaProcessors.Add( new SwaggerSchemaProcessor () );
                               } );

I am pretty sure I am missing something really simple but I do not get it. Any help really appreciated.

I successfully filtered out the controllers referencing the models that I want to hide using an OperationProcessor.

jeremyVignelles commented 3 years ago

@sascha-andres : You should probably open your own issue.

Do you need to exclude them at schema generation or at client code generation? In the second case there is another option for that.

sascha-andres commented 3 years ago

@jeremyVignelles I want to exclude the models at schema generation time. Will open another issue ( opened: #3178 )

Oglan commented 3 years ago

Sorry for the late response.

I was talking about SwaggerUI filter option actually. Described here: https://github.com/swagger-api/swagger-ui/blob/v3.8.1/docs/usage/configuration.md#display

I didn't find how to enable it in the NSwag.

kasperskov909 commented 1 year ago

@sascha-andres : You should probably open your own issue.built

Do you need to exclude them at schema generation or at client code generation? In the second case there is another option for that.

What's the option for client code generation? Can't find anything suggesting there's a built-in filter option.