35

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);
    }
}

7 Answers 7

52

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

1
26

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

1
  • 1
    it's helpful to change this at query time.
    – liang
    Apr 16, 2020 at 5:38
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

5

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).
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
        );
    }
1

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

springdoc.swagger-ui.docExpansion=full

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.