在 SpringDoc 中设置 swagger 配置参数
Setting swagger config parameters in SpringDoc
我正在尝试覆盖 SpringDoc 中的 Swagger 配置,如下所述:
https://springdoc.org/#swagger-ui-properties
我在 (kotlin class) init 块的代码中设置这些
init {
System.setProperty("springdoc.swagger-ui.path", "/services/$serviceName")
System.setProperty("springdoc.swagger-ui.url", "/services/$serviceName/v3/api-docs")
System.setProperty("springdoc.swagger-ui.configUrl", "/services/$serviceName/v3/api-docs/swagger-config")
// Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters.
System.setProperty("springdoc.swagger-ui.showCommonExtensions", "true")
}
但是它似乎被完全忽略了,none 的字段被考虑在内。这些应该在什么地方设置正确?
请注意,我需要根据 SERVICE_NAME
env var 设置配置属性,因此我无法使用静态属性文件。
此处为完整配置:https://gist.github.com/knyttl/852f67f1688ea6e808b8eb89068e90d1
正如 SpringDoc 作者在 https://github.com/springdoc/springdoc-openapi/issues/1485 中所建议的,可以按如下方式完成:
@Bean
open fun swaggerUiConfig(config: SwaggerUiConfigProperties): SwaggerUiConfigProperties {
// For details, see https://springdoc.org/#swagger-ui-properties
// Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters.
config.showCommonExtensions = true
// Allows to configure source for the documentation via query params (?url=/v3/api-docs).
config.queryConfigEnabled = true
return config
}
我正在尝试覆盖 SpringDoc 中的 Swagger 配置,如下所述:
https://springdoc.org/#swagger-ui-properties
我在 (kotlin class) init 块的代码中设置这些
init {
System.setProperty("springdoc.swagger-ui.path", "/services/$serviceName")
System.setProperty("springdoc.swagger-ui.url", "/services/$serviceName/v3/api-docs")
System.setProperty("springdoc.swagger-ui.configUrl", "/services/$serviceName/v3/api-docs/swagger-config")
// Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters.
System.setProperty("springdoc.swagger-ui.showCommonExtensions", "true")
}
但是它似乎被完全忽略了,none 的字段被考虑在内。这些应该在什么地方设置正确?
请注意,我需要根据 SERVICE_NAME
env var 设置配置属性,因此我无法使用静态属性文件。
此处为完整配置:https://gist.github.com/knyttl/852f67f1688ea6e808b8eb89068e90d1
正如 SpringDoc 作者在 https://github.com/springdoc/springdoc-openapi/issues/1485 中所建议的,可以按如下方式完成:
@Bean
open fun swaggerUiConfig(config: SwaggerUiConfigProperties): SwaggerUiConfigProperties {
// For details, see https://springdoc.org/#swagger-ui-properties
// Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters.
config.showCommonExtensions = true
// Allows to configure source for the documentation via query params (?url=/v3/api-docs).
config.queryConfigEnabled = true
return config
}