flask-restplus
flask-restplus copied to clipboard
Hide models from the buttom of the swagger ui
I would like to hide the models section from the swagger website. in the swagger doc the is an option to disable it by setting the param "DEFAULT_MODELS_EXPAND_DEPTH" to -1. I tried to do it here also but nothing works. can you add it please?
Unfortunately no. still waiting for a solution.
@nunidoron Not the best way to do it but there is a hack using CSS in your API description below:
Api(app=app, title='API', description='API <style>.models {display: none !important}</style>'
@tiagobarreto you are so creative :) that one really did the job done. thank you 👍
This is currently possible in Swashbuckle.AspNetCore
version 5.0.0-rc4
app.UseSwaggerUI(c =>
{
...
c.DefaultModelsExpandDepth(-1); // hide completely
// c.DefaultModelsExpandDepth(0); // collapse
...
});
@nunidoron Not the best way to do it but there is a hack using CSS in your API description below:
Api(app=app, title='API', description='API <style>.models {display: none !important}</style>'
This is the funniest solution I've ever seen. Well done my friend hahaa
that can also be hidden by a custom ISchemaFilter Class Somehow its not working with me in .Net 5.0 so I did this way.
`using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;
namespace YourNamespace
{
///
///
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
foreach (var key in context.SchemaRepository.Schemas.Keys)
{
if(!VisibleSchemas.Contains(key))
context.SchemaRepository.Schemas.Remove(key);
}
}
}
}`
Then in Startup.cs class
services.AddSwaggerGen(c => { c.SchemaFilter<SchemasVisibility>(); }
In your serializer just define in meta class ref_name = None