You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何自定义Open API定义分组顺序并设置Swagger UI默认选中组

让Swagger UI默认选中自定义的custom分组

针对JHipster生成的响应式Spring Boot应用,要让新增的custom分组在Swagger UI加载时默认选中,可通过以下两种方式实现:

方法一:Java配置类设置

在Swagger相关配置类中,注入SwaggerUiConfigParameters并指定默认分组:

import org.springdoc.core.SwaggerUiConfigParameters;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CustomSwaggerConfig {

    public CustomSwaggerConfig(SwaggerUiConfigParameters swaggerUiConfigParameters) {
        // 设置默认选中分组为"custom"
        swaggerUiConfigParameters.setDefaultGroup("custom");
    }

    // 你的自定义分组Bean
    @Bean
    public GroupedOpenApi petOpenApi() {
        String paths[] = {"/pet/**"};
        return GroupedOpenApi.builder().group("custom").pathsToMatch(paths)
                .build();
    }
}

方法二:配置文件设置

在application.yml(或application.properties)中添加SpringDoc配置项,直接指定默认分组:

springdoc:
  swagger-ui:
    default-group: custom

完成配置后,Swagger UI页面加载时会自动选中custom分组,无需手动切换。

内容的提问来源于stack exchange,提问作者Abin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 15:18:59