|
@@ -0,0 +1,68 @@
|
|
|
+package com.gxzc.zen.common.config
|
|
|
+
|
|
|
+import io.swagger.annotations.ApiOperation
|
|
|
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
|
|
+import org.springframework.context.annotation.Bean
|
|
|
+import org.springframework.context.annotation.Configuration
|
|
|
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
|
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
|
|
+import springfox.documentation.builders.ApiInfoBuilder
|
|
|
+import springfox.documentation.builders.PathSelectors
|
|
|
+import springfox.documentation.builders.RequestHandlerSelectors
|
|
|
+import springfox.documentation.service.ApiInfo
|
|
|
+import springfox.documentation.service.ApiKey
|
|
|
+import springfox.documentation.service.Contact
|
|
|
+import springfox.documentation.spi.DocumentationType
|
|
|
+import springfox.documentation.spring.web.plugins.Docket
|
|
|
+import springfox.documentation.swagger2.annotations.EnableSwagger2
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * swagger-ui 配置
|
|
|
+ * @author NorthLan
|
|
|
+ * @date 2018/2/10
|
|
|
+ * @url https://noahlan.com
|
|
|
+ */
|
|
|
+@Configuration
|
|
|
+@EnableSwagger2
|
|
|
+@ConditionalOnProperty(prefix = "zen", name = ["swagger-open"], havingValue = "true")
|
|
|
+class SwaggerConfig : WebMvcConfigurerAdapter() {
|
|
|
+
|
|
|
+ override fun addResourceHandlers(registry: ResourceHandlerRegistry?) {
|
|
|
+ registry?.let {
|
|
|
+ it.addResourceHandler("swagger-ui.html")
|
|
|
+ .addResourceLocations("classpath:/META-INF/resources/")
|
|
|
+ it.addResourceHandler("/webjars*")
|
|
|
+ .addResourceLocations("classpath:/META-INF/resources/webjars/")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ fun createApi(): Docket {
|
|
|
+ return Docket(DocumentationType.SWAGGER_2)
|
|
|
+ .groupName("v2")
|
|
|
+ .apiInfo(apiInfo())
|
|
|
+ .select()
|
|
|
+ .apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation::class.java))
|
|
|
+ .paths(PathSelectors.ant("/api/v2/**"))
|
|
|
+ .build()
|
|
|
+// .securitySchemes()
|
|
|
+ }
|
|
|
+
|
|
|
+ @Suppress("UNUSED")
|
|
|
+ private fun apiKey(): ApiKey {
|
|
|
+ return ApiKey("Bearer ", "Authorization", "header")
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun apiInfo(): ApiInfo {
|
|
|
+ return ApiInfoBuilder()
|
|
|
+ .title("Zen Doc")
|
|
|
+ .description("Zen Api Document")
|
|
|
+ .termsOfServiceUrl("")
|
|
|
+ .contact(Contact("NorthLan", "https://noahlan.com", "lan6995@gmail.com"))
|
|
|
+ .version("2.0")
|
|
|
+ .license("!!!private!!!")
|
|
|
+ .build()
|
|
|
+ }
|
|
|
+}
|