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

7

38

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);
    }
}
Janiecejanifer answered 27/11, 2015 at 0:21 Comment(0)
P
54

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

Prepay answered 28/11, 2015 at 7:38 Comment(1)
Updated doc link: github.com/swagger-api/swagger-ui/blob/master/docs/usage/…Jackiejackinoffice
B
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).

Benil answered 5/3, 2019 at 8:59 Comment(1)
it's helpful to change this at query time.Duckboard
W
10

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

Weedy answered 11/10, 2018 at 13:39 Comment(0)
V
6

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.

    });
}
Veneaux answered 8/6, 2022 at 14:2 Comment(0)
T
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).
Tetradymite answered 24/5, 2018 at 5:58 Comment(0)
I
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
        );
    }
Inundate answered 27/6, 2017 at 8:14 Comment(0)
C
1

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

springdoc.swagger-ui.docExpansion=full

Cherokee answered 9/2, 2023 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.