Commit 790e31b3 authored by Ghitha Dinan's avatar Ghitha Dinan

add swagger config

parent e9d4fa9b
...@@ -97,6 +97,19 @@ ...@@ -97,6 +97,19 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.32</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -6,6 +6,8 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean ...@@ -6,6 +6,8 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.CorsRegistry import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
...@@ -26,8 +28,8 @@ class SpringWebConfig : WebMvcConfigurer { ...@@ -26,8 +28,8 @@ class SpringWebConfig : WebMvcConfigurer {
FilterRegistrationBean<TokenInterceptor>() FilterRegistrationBean<TokenInterceptor>()
AUDIENCE_FILTER_PATH.forEach { AUDIENCE_FILTER_PATH.forEach {
it.value.forEach { it.value.forEach { it2 ->
registrationBean.addUrlPatterns(it) registrationBean.addUrlPatterns(it2)
} }
} }
...@@ -35,4 +37,20 @@ class SpringWebConfig : WebMvcConfigurer { ...@@ -35,4 +37,20 @@ class SpringWebConfig : WebMvcConfigurer {
registrationBean.order = 1 registrationBean.order = 1
return registrationBean return registrationBean
} }
override fun addViewControllers(registry: ViewControllerRegistry) {
registry.addRedirectViewController("/v2/api-docs", "/v2/api-docs")
registry.addRedirectViewController("/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui")
registry.addRedirectViewController(
"/swagger-resources/configuration/security",
"/swagger-resources/configuration/security"
)
registry.addRedirectViewController("/swagger-resources", "/swagger-resources")
}
override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
registry.addResourceHandler("/swagger-ui.html**")
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html")
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/")
}
} }
package id.co.sangkuriang.inovasi.daerah.master.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.service.*
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spi.service.contexts.SecurityContext
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2
import java.util.*
@Suppress("UNCHECKED_CAST", "DEPRECATION")
@Configuration
@EnableSwagger2
class SwaggerConfig {
@Value("\${swagger.host}")
private val host: String? = null
@Value("\${swagger.protocol}")
private val protocol: String? = null
@Bean
fun api(): Docket? {
return Docket(DocumentationType.SWAGGER_2)
.host(host)
.select()
.apis(RequestHandlerSelectors.basePackage("id.co.sangkuriang.inovasi.daerah.master.controller"))
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false)
.apiInfo(apiInfo())
.protocols(setOf(protocol))
.securitySchemes(listOf(apiKey()) as List<SecurityScheme>?)
.securityContexts(Collections.singletonList(securityContext()))
}
private fun apiInfo(): ApiInfo {
return ApiInfo(
"Inovasi Daerah API - Master",
"Api Service for Application Inovasi Daerah Master",
"1.0",
"Terms of service",
Contact("Inovasi Daerah", "https://cms.inovasi-daerah.dev.layanan.go.id", "inovasi-daerah@gmail.com"),
"",
"",
Collections.emptyList()
)
}
private fun apiKey(): ApiKey {
return ApiKey("Bearer", "Authorization", "header")
}
private fun securityContext(): SecurityContext? {
return SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.regex("/.*")).build()
}
private fun defaultAuth(): List<SecurityReference?> {
return listOf(SecurityReference("Bearer", arrayOfNulls(0)))
}
}
...@@ -2,8 +2,8 @@ package id.co.sangkuriang.inovasi.daerah.master.constant ...@@ -2,8 +2,8 @@ package id.co.sangkuriang.inovasi.daerah.master.constant
import java.io.File import java.io.File
//const val ROOT_DIR = "D:\\app-files\\inovasi_daerah_master\\files\\" const val ROOT_DIR = "D:\\app-files\\inovasi_daerah_master\\files\\"
const val ROOT_DIR = "/home/inovasi-daerah/data/files/inovasi_daerah_master/" //const val ROOT_DIR = "/home/inovasi-daerah/data/files/inovasi_daerah_master/"
//const val ROOT_DIR = "/home/inovasi-daerah-prod/data/files/inovasi_daerah_master/" //const val ROOT_DIR = "/home/inovasi-daerah-prod/data/files/inovasi_daerah_master/"
val UPLOAD_DIR = "${ROOT_DIR}uploads${File.separator}" val UPLOAD_DIR = "${ROOT_DIR}uploads${File.separator}"
......
...@@ -3,8 +3,8 @@ package id.co.sangkuriang.inovasi.daerah.master.constant ...@@ -3,8 +3,8 @@ package id.co.sangkuriang.inovasi.daerah.master.constant
const val TOKEN_PREFIX = "Bearer " const val TOKEN_PREFIX = "Bearer "
const val HEADER_STRING = "Authorization" const val HEADER_STRING = "Authorization"
//const val AUTH_URL = "http://localhost:8081/auth" //const val AUTH_URL = "http://localhost:8081/auth"
//const val AUTH_URL = "https://auth.inovasi-daerah.dev.layanan.go.id/auth" const val AUTH_URL = "https://auth.inovasi-daerah.dev.layanan.go.id/auth"
const val AUTH_URL = "http://inovasi-daerah-auth.inovasi-daerah.svc.cluster.local:8081/auth" //const val AUTH_URL = "http://inovasi-daerah-auth.inovasi-daerah.svc.cluster.local:8081/auth"
//const val AUTH_URL = "http://inovasi-daerah-auth-prod.inovasi-daerah-prod.svc.cluster.local:8081/auth" //const val AUTH_URL = "http://inovasi-daerah-auth-prod.inovasi-daerah-prod.svc.cluster.local:8081/auth"
val USER_ALLOWED_PATH = emptyList<String>() val USER_ALLOWED_PATH = emptyList<String>()
......
...@@ -2,6 +2,6 @@ package id.co.sangkuriang.inovasi.daerah.master.constant ...@@ -2,6 +2,6 @@ package id.co.sangkuriang.inovasi.daerah.master.constant
//const val APPLICATION_URL = "http://localhost:8082" //const val APPLICATION_URL = "http://localhost:8082"
//const val APPLICATION_URL = "https://application.inovasi-daerah.dev.layanan.go.id" //const val APPLICATION_URL = "https://application.inovasi-daerah.dev.layanan.go.id"
const val APPLICATION_URL = "http://inovasi-daerah-application.inovasi-daerah.svc.cluster.local:8082" //const val APPLICATION_URL = "http://inovasi-daerah-application.inovasi-daerah.svc.cluster.local:8082"
//const val APPLICATION_URL = "http://inovasi-daerah-application-prod.inovasi-daerah-prod.svc.cluster.local:8082" const val APPLICATION_URL = "http://inovasi-daerah-application-prod.inovasi-daerah-prod.svc.cluster.local:8082"
...@@ -5,14 +5,14 @@ server.port=8080 ...@@ -5,14 +5,14 @@ server.port=8080
# DATABASE CONFIG # DATABASE CONFIG
# local # local
#spring.datasource.url=jdbc:postgresql://localhost:5432/inovasi_daerah_backup spring.datasource.url=jdbc:postgresql://localhost:5432/inovasi_daerah_backup
#spring.datasource.username=postgres spring.datasource.username=postgres
#spring.datasource.password=root spring.datasource.password=root
# dev # dev
spring.datasource.url=jdbc:postgresql://pg.dev.layanan.go.id:5432/inovasi_daerah_db #spring.datasource.url=jdbc:postgresql://pg.dev.layanan.go.id:5432/inovasi_daerah_db
spring.datasource.username=u_inovasi_daerah #spring.datasource.username=u_inovasi_daerah
spring.datasource.password=wV9Tnx6S8TmmUYXdgkmN4pzreSD3RE #spring.datasource.password=wV9Tnx6S8TmmUYXdgkmN4pzreSD3RE
# prod # prod
#spring.datasource.url=jdbc:postgresql://pg.prd.layanan.go.id:5432/inovasi_daerah_db #spring.datasource.url=jdbc:postgresql://pg.prd.layanan.go.id:5432/inovasi_daerah_db
...@@ -35,3 +35,7 @@ spring.servlet.multipart.max-request-size=500MB ...@@ -35,3 +35,7 @@ spring.servlet.multipart.max-request-size=500MB
# APP CONFIG # APP CONFIG
server.max-http-header-size=10000KB server.max-http-header-size=10000KB
# Swagger
swagger.host=localhost:8080
swagger.protocol=http
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
<!-- configuration file for LogBack (slf4J implementation) <!-- configuration file for LogBack (slf4J implementation)
See here for more details: http://gordondickens.com/wordpress/2013/03/27/sawing-through-the-java-loggers/ --> See here for more details: http://gordondickens.com/wordpress/2013/03/27/sawing-through-the-java-loggers/ -->
<configuration scan="true" scanPeriod="30 seconds"> <configuration scan="true" scanPeriod="30 seconds">
<!-- <property name="DEV_HOME" value="D://app-files//inovasi_daerah_master//log"/>--> <property name="DEV_HOME" value="D://app-files//inovasi_daerah_master//log"/>
<property name="DEV_HOME" value="/home/inovasi-daerah/data/log/inovasi_daerah_master"/> <!-- <property name="DEV_HOME" value="/home/inovasi-daerah/data/log/inovasi_daerah_master"/>-->
<!-- <property name="DEV_HOME" value="/home/inovasi-daerah-prod/data/log/inovasi_daerah_master"/>--> <!-- <property name="DEV_HOME" value="/home/inovasi-daerah-prod/data/log/inovasi_daerah_master"/>-->
<appender name="ACCESS-LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <appender name="ACCESS-LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment