34

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);
    }
}
Gerardo Martínez
  • 793
  • 2
  • 12
  • 26

7 Answers7

50

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

Xin Meng
  • 1,982
  • 3
  • 20
  • 32
fehguy
  • 6,724
  • 25
  • 23
  • 1
    Updated doc link: https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#display – dpmott Aug 21 '19 at 20:25
25

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

Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154
9

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

Tristan
  • 8,733
  • 7
  • 48
  • 96
4

For .NET Core/Framework using C#,

You can simply configure the Document Expansion/UnExpansion as given below

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    
    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "Fire Cloud Client Authentication Service API V1.0");
        c.DocExpansion(DocExpansion.None);//This will not expand all the API's.

    });
}
3

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).
JR Sahoo.'JS'
  • 1,338
  • 2
  • 10
  • 11
2
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
        );
    }
membersound
  • 81,582
  • 193
  • 585
  • 1,120
1

in case if you use springdoc, this property can be helpful.

springdoc.swagger-ui.docExpansion=full