swagger-ui.html更改,spring boot - How to change swagger-ui.html default path - Stack Overflow

If you want to add, for example, documentation prefix - You can do like this for path http://localhost:8080/documentation/swagger-ui.html:

kotlin

@Configuration

@EnableSwagger2

@ConfigurationPropertiesScan("your.package.config")

@Import(value = [BeanValidatorPluginsConfiguration::class])

class SwaggerConfiguration(

private val swaggerContactProp: SwaggerContactProp, private val swaggerProp: SwaggerProp

) : WebMvcConfigurationSupport() {

// https://springfox.github.io/springfox/docs/current/

@Bean

fun api(): Docket = Docket(DocumentationType.SWAGGER_2)

.groupName("Cards")

.apiInfo(getApiInfo())

.select()

.apis(RequestHandlerSelectors.basePackage("your.controllers.folder"))

.paths(PathSelectors.any())

.build()

private fun getApiInfo(): ApiInfo {

val contact = Contact(swaggerContactProp.name, swaggerContactProp.url, swaggerContactProp.mail)

return ApiInfoBuilder()

.title(swaggerProp.title)

.description(swaggerProp.description)

.version(swaggerProp.version)

.contact(contact)

.build()

}

override fun addViewControllers(registry: ViewControllerRegistry) {

with(registry) {

addRedirectViewController("/documentation/v2/api-docs", "/v2/api-docs").setKeepQueryParams(true)

addRedirectViewController(

"/documentation/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui"

)

addRedirectViewController(

"/documentation/swagger-resources/configuration/security", "/swagger-resources/configuration/security"

)

addRedirectViewController("/documentation/swagger-resources", "/swagger-resources")

}

}

override fun addResourceHandlers(registry: ResourceHandlerRegistry) {

registry.addResourceHandler("/documentation/**").addResourceLocations("classpath:/META-INF/resources/")

}

}

@ConfigurationProperties(prefix = "swagger")

@ConstructorBinding

data class SwaggerProp(val title: String, val description: String, val version: String)

@ConfigurationProperties(prefix = "swagger.contact")

@ConstructorBinding

data class SwaggerContactProp(val mail: String, val url: String, val name: String)

and in applicatiom.yml:

swagger:

title: Cards

version: 1.0

description: Documentation for API

contact:

mail: email@gmail.com

url: some-url.com

name: COLABA card

Also don't forget to add in build.gradle.kts:

implementation("io.springfox:springfox-swagger2:$swagger")

implementation("io.springfox:springfox-swagger-ui:$swagger")

implementation("io.springfox:springfox-bean-validators:$swagger")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值