springdoc-openapi Schema数据类型默认不展开的配置解决咨询
解决方案
要让SpringDoc OpenAPI UI的Schema区域数据类型默认展开,只需添加以下配置即可:
方式1:通过配置文件(application.properties/yaml)
在项目配置文件中添加属性:
# 控制模型列表的展开深度,2表示展开所有层级 springdoc.swagger-ui.defaultModelsExpandDepth=2 # 控制单个模型内部属性的展开深度,2表示展开所有嵌套属性 springdoc.swagger-ui.defaultModelExpandDepth=2
若使用YAML格式:
springdoc: swagger-ui: default-models-expand-depth: 2 default-model-expand-depth: 2
方式2:通过Java配置类
如果偏好代码配置,可在你的SwaggerConfiguration类中添加SwaggerUiConfigProperties的Bean:
@Configuration class SwaggerConfiguration { @Bean public OpenAPI openAPI() { return new OpenAPI() .info( new Info().title("Delta Gateway") .description("API service for delta-gateway to perform various operations over Products, Articles, Enrichment, Labels etc") .version("v0.0.1") ) .externalDocs( new ExternalDocumentation() .description("ESL Gateway documentation") .url("https://docs.csnzoo.com/shared/abc/app/delta-gateway/") ); } @Bean public SwaggerUiConfigProperties swaggerUiConfigProperties() { SwaggerUiConfigProperties uiConfig = new SwaggerUiConfigProperties(); // 设置模型列表展开深度,-1为完全折叠,0仅展开根,2展开所有层级 uiConfig.setDefaultModelsExpandDepth(2); // 设置单个模型内部展开深度,2为展开所有嵌套属性 uiConfig.setDefaultModelExpandDepth(2); return uiConfig; } }
参数说明
defaultModelsExpandDepth:控制左侧模型列表的展开层级,设为2会展开所有嵌套模型;defaultModelExpandDepth:控制单个模型详情页中属性的展开层级,设为2会展开所有嵌套属性结构。
可根据实际需求调整数值,比如仅展开第一层级就设为1。
内容的提问来源于stack exchange,提问作者cbot
相关产品推荐
相关产品推荐

