Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the Models section in Swagger UI?

Tags:

swagger-ui

I use Swagger UI to display API documentation. By default, it displays the "Models" section at the bottom:

enter image description here

How to hide it?

like image 288
02040402 Avatar asked Jul 22 '19 02:07

02040402


People also ask

How do I hide models in swagger spring boot?

Using @ApiModelProperty We can use the hidden property of the annotation to hide a field in the definition of a model object in Swagger UI. Let's try it for the id field: @ApiModelProperty(hidden = true) private int id; In the above scenarios, we find that the id field is hidden for both GET and POST APIs.

How do I hide the schema in swagger net core?

How to do it? add this property in your Swagger UI Options defaultModelsExpandDepth: -1 for hide schema section and for more reference refer this swagger.io/docs/open-source-tools/swagger-ui/usage/… Can you please add your swagger ui configuration settings in your question.

Can we customize Swagger UI?

By default, Swagger UI uses BaseLayout , which is built into the application. You can specify a different layout to be used by passing the layout's name as the layout parameter to Swagger UI. Be sure to provide your custom layout as a component to Swagger UI.


2 Answers

To hide the "Models" section, add defaultModelsExpandDepth: -1 to the Swagger UI configuration code in your index.html.

Note the option name uses plural Model*s* not Model.

// index.html

<script>
window.onload = function() {
  // Begin Swagger UI call region
  const ui = SwaggerUIBundle({
    url: "https://petstore.swagger.io/v2/swagger.json",
    dom_id: '#swagger-ui',
    defaultModelsExpandDepth: -1,   // <-------

Swagger UI also has many other configuration options that control API documentation rendering.

like image 92
Helen Avatar answered Oct 26 '22 15:10

Helen


For .Net Core 3.0 just Add c.DefaultModelsExpandDepth(-1); on your Startup.cs

// Startup.cs

app.UseSwaggerUI(c =>
{
    c.DefaultModelsExpandDepth(-1); // Disable swagger schemas at bottom
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Your API V1");
});
like image 45
Jaime Torner Avatar answered Oct 26 '22 16:10

Jaime Torner