Swagger UI - How can I expand all the operations by default?

23,332

Solution 1

I believe you can set the docExpansion:"full" when creating swagger-ui.

See https://github.com/swagger-api/swagger-ui#parameters for details.

docExpansion: Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing). The default is 'list'.

Solution 2

I just found out I actually can pass the parameter to the swagger url like so:

http://...../swagger/index.html?docExpansion=none

docExpansion : "none" - hide everything.

docExpansion : "list"- expand/List all the operations only.

docExpansion : "full" - expand everything (full expand as the name says).

Solution 3

Here is the answer with Springfox which is what you seem to use :

  @Bean
  UiConfiguration uiConfig() {
    return UiConfigurationBuilder.builder()
        .docExpansion(DocExpansion.LIST) // or DocExpansion.NONE or DocExpansion.FULL
        .build();
  }  

source : http://springfox.github.io/springfox/docs/current/#springfox-swagger2-with-spring-mvc-and-spring-boot

Solution 4

I did it by adding the required changes in the swaggerUi. You need to change it as per your requirement as below;

  1. docExpansion : "none" - It'll Hide everything.
  2. docExpansion : "list"- It'll expand/List all the operations only.
  3. docExpansion : "full" - It'll expand everything(Full expand as the name says).

Solution 5

private static final String DOC_EXPANSION = "list"; //none, full

    @Bean
    public UiConfiguration uiConfig() {
        return new UiConfiguration(
                null, DOC_EXPANSION, "alpha", "schema", UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, false, true, null
        );
    }
Share:
23,332

Related videos on Youtube

Gemasoft
Author by

Gemasoft

DE DÍA: Application Development Manager @O'Reilly con experiencia en Google Cloud Platform, mayormente en App Engine y Datastore, con varios años de experiencia en VB, C#, .NET MVC, Java, Spring MVC, Hibernate, Angular, NodeJs, MSSQL, MySQL y PostgreSQL, también algo de Android. DE NOCHE: Desarrollador de Juegos indie en Unity con C#, Hardcore Gamer y Creador de Contenido con +190k followers en @Facebook, aficionado de las desveladas y alérgico a los perros.

Updated on April 16, 2020

Comments

  • Gemasoft
    Gemasoft about 4 years

    All the operations appear collapsed when I open it and I want it to be expanded by default.

    Is there any property I need to change to achieve it?

    This is my swagger Bean:

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    
        @Bean
        public Docket restApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .paths(regex("/api/.*"))
                    .build()
                    .directModelSubstitute(XMLGregorianCalendar.class, Date.class)
                    .apiInfo(apiInfo())                
                    .useDefaultResponseMessages(false);
        }
    }
    
  • dpmott
    dpmott over 4 years
  • liang
    liang about 4 years
    it's helpful to change this at query time.