Reputation: 1379
I have followed the top article : .Net Core 3.1 Remove Schema on Swagger UI
I applied this filter:
public class RemoveSchemasFilter : IDocumentFilter
{
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
IDictionary<string, OpenApiSchema> _remove = swaggerDoc.Components.Schemas;
foreach (KeyValuePair<string, OpenApiSchema> _item in _remove)
{
swaggerDoc.Components.Schemas.Remove(_item.Key);
}
}
}
I have added it here:
services.AddSwaggerGen(options =>
{
options.OperationFilter<AddRequiredHeaderParameter>(Configuration.GetSection("DefaultConfig")["TenantId"]);
options.DocumentFilter<RemoveSchemasFilter>();
}
All good Schema is removed from the bottom of Swagger UI. However, when I click on a method it brings a dialogue of errors. It works but this windows stays on top and it is very annoying.
Let's solve this problem together as it was unsolved previously!
Upvotes: 5
Views: 3436
Reputation: 1379
The schema filter is useless.
All needs to be done is in
app.UseSwaggerUI(options =>
{
options.DefaultModelsExpandDepth(-1);
}
Note: It is Default Models not Default Model. DIfference is DefaultModel is the default expansion depth for the model on the model-example section, whereas DefaultModels is the expansion depth for models.
Upvotes: 2