如何自定义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
相关产品推荐
相关产品推荐

