【问题标题】:Swagger UI - How can I expand all the operations by default?Swagger UI - 默认情况下如何扩展所有操作?
【发布时间】:2016-03-01 03:29:52
【问题描述】:

我打开时所有操作都显示为折叠状态,我希望它默认展开。

我需要更改任何属性来实现它吗?

这是我的招摇豆:

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

【问题讨论】:

    标签: spring api spring-mvc swagger swagger-ui


    【解决方案1】:

    我相信你可以在创建 swagger-ui 时设置docExpansion:"full"

    详情请见https://github.com/swagger-api/swagger-ui#parameters

    docExpansion:控制操作和标签的默认扩展设置。它可以是“list”(仅扩展标签)、“full”(扩展标签和操作)或“none”(不扩展任何内容)。默认为“列表”。

    【解决方案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
            );
        }
    

    【讨论】:

      【解决方案3】:

      我通过在 swaggerUi 中添加所需的更改来做到这一点。 您需要根据您的要求进行更改,如下所示;

      1. docExpansion : "none" - 它会隐藏所有内容。
      2. docExpansion : "list"- 它只会展开/列出所有操作。
      3. docExpansion : "full" - 它将扩展所有内容(如名称所述完全扩展)。

      【讨论】:

        【解决方案4】:

        这是您似乎使用的 Springfox 的答案:

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

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

        【讨论】:

          【解决方案5】:

          我刚刚发现我实际上可以像这样将参数传递给 swagger url:

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

          docExpansion : "none" - 隐藏所有内容。

          docExpansion : "list"- 仅展开/列出所有操作。

          docExpansion : "full" - 展开所有内容(顾名思义完全展开)。

          【讨论】:

          • 在查询时更改它会很有帮助。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-21
          相关资源
          最近更新 更多