How to Omit Methods from Swagger Documentation on Webapi Using Swashbuckle

Exclude particular Web Api endpoint from the swagger UI

You can add the following attribute to Controllers and Actions to exclude them from the generated documentation: [ApiExplorerSettings(IgnoreApi = true)]

Summary of the method documentation is not showing in Swagger UI

Here's what worked on my side (in a sample .NET 6 Web Api project):

  1. Go to the properties of your project => Build => General => Output section => Tick the checkbox 'XML Documentation file'

  2. Edit the AddSwaggerGen service configuration by adding the following:

builder.Services.AddSwaggerGen(c =>
{
...

var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});

PoC:
Sample Image

Does this approach work for you?

Get Swashbuckle/Swagger route programmatically

Based on @lonix comment, Converting to Ans.

In case UseSwagger(), it does not create any endpoint but a middleware so when you call "/swagger", it checks request for swagger document and returns swagger document if found true. but in case of MapSwagger() it actually creates endpoint.

and yes you can swap it without breaking anything.

.Net Core 3.1 Remove Schema on Swagger UI

No need for a schema filter. After busting on it for days I have found out:

All needs to be done is in

app.UseSwaggerUI(options =>
{
options.DefaultModelsExpandDepth(-1);
});

Note: It is DefaultModels (plural) not DefaultModel (singular). Difference is DefaultModels is the default expansion depth for the model on the model-example section, whereas DefaultModels is the expansion depth for models.



Related Topics



Leave a reply



Submit