swagger-ui

How to hide the Models section in 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?


Solution

  • 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.