24

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?

Helen
  • 87,344
  • 17
  • 243
  • 314
02040402
  • 729
  • 3
  • 6
  • 21

6 Answers6

26

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.

Helen
  • 87,344
  • 17
  • 243
  • 314
17

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");
});
Jaime Torner
  • 241
  • 2
  • 2
5

In Docket bean just add new

Docket(DocumentationType.SWAGGER_2).ignoredParameterTypes(YourClass.class,YourAnother.class)

I hope its helpful

Jaimil Patel
  • 1,301
  • 6
  • 13
ImI
  • 198
  • 1
  • 8
2

Using Spring Boot:

@Bean
public UiConfiguration uiConfiguration() {
    return UiConfigurationBuilder//
            .builder()//
            .defaultModelsExpandDepth(-1)//
            .build();//
}
1

If using Django add this inside your settings.py:

SWAGGER_SETTINGS = {
    'DEFAULT_MODEL_DEPTH':-1
}
PSN
  • 2,326
  • 3
  • 27
  • 52
-2

Although not the exact results you are looking for but i find it perfect to just disable the properties of the model you don't want via:

<?php
// src/AppBundle/Entity/User.php

use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;

...

 * @ApiResource(
 *     attributes={
 *         "normalization_context"={"groups"={"api"}},
 *         "denormalization_context"={"groups"={"api"}}
 *     },

...

 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @Groups({"api","user:read"})
     */
    protected $id;

    /**
     * @var \DateTime
     */
    private $disabledProperty;

This way you will get a model just with the props you exposed via the group api. Hope this helps someone :)

numediaweb
  • 16,362
  • 12
  • 74
  • 110