How to hide the Models section in Swagger UI?

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.

Leave a Comment