Commit 33c81657 authored by Ghitha Dinan's avatar Ghitha Dinan

add swagger config

parent e8877270
...@@ -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
...@@ -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.go.kemenag.madrasah.pmrms.auth.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.go.kemenag.madrasah.pmrms.auth.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(
"PMRMS API - Auth",
"Auth Service for Application PMRMS",
"1.0",
"Terms of service",
Contact("Application PMRMS", "-", "-"),
"",
"",
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)))
}
}
package id.go.kemenag.madrasah.pmrms.auth.contoller package id.go.kemenag.madrasah.pmrms.auth.controller
import id.go.kemenag.madrasah.pmrms.auth.model.request.auth.LoginRequest import id.go.kemenag.madrasah.pmrms.auth.model.request.auth.LoginRequest
import id.go.kemenag.madrasah.pmrms.auth.model.response.ReturnData import id.go.kemenag.madrasah.pmrms.auth.model.response.ReturnData
import id.go.kemenag.madrasah.pmrms.auth.service.AuthService import id.go.kemenag.madrasah.pmrms.auth.service.AuthService
import io.swagger.annotations.Api
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.* import org.springframework.web.bind.annotation.*
import javax.validation.Valid import javax.validation.Valid
@Api(tags = ["Auth"], description = "Auth API")
@RestController @RestController
@RequestMapping(path = ["auth"]) @RequestMapping(path = ["auth"])
class AuthController { class AuthController {
......
package id.go.kemenag.madrasah.pmrms.auth.contoller package id.go.kemenag.madrasah.pmrms.auth.controller
import id.go.kemenag.madrasah.pmrms.auth.exception.BaseException import id.go.kemenag.madrasah.pmrms.auth.exception.BaseException
import id.go.kemenag.madrasah.pmrms.auth.model.response.ErrorMessage import id.go.kemenag.madrasah.pmrms.auth.model.response.ErrorMessage
......
# SERVER CONFIG # SERVER CONFIG
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
spring.profiles.active=development spring.profiles.active=development
server.port=8080 #server.port=8080
server.port=8081
# DATABASE CONFIG # DATABASE CONFIG
# local # local
...@@ -28,13 +29,6 @@ spring.jpa.properties.hibernate.format_sql=true ...@@ -28,13 +29,6 @@ spring.jpa.properties.hibernate.format_sql=true
spring.servlet.multipart.max-file-size=500MB spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB spring.servlet.multipart.max-request-size=500MB
# MAIl CONFIG
spring.mail.host=mail.smtp2go.com
spring.mail.port=2525
spring.mail.username=kominfo-05
spring.mail.password=eXFwenN6cm4yYmMw
spring.mail.from=no-reply@layanan.go.id
spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=25000 spring.mail.properties.mail.smtp.connectiontimeout=25000
spring.mail.properties.mail.smtp.timeout=25000 spring.mail.properties.mail.smtp.timeout=25000
...@@ -45,3 +39,8 @@ spring.mail.properties.mail.smtp.starttls.enable=true ...@@ -45,3 +39,8 @@ spring.mail.properties.mail.smtp.starttls.enable=true
app.name = PMRMS app.name = PMRMS
server.max-http-header-size=10000KB server.max-http-header-size=10000KB
# Swagger
swagger.host=localhost:8081
swagger.protocol=http
spring.main.allow-circular-references= true
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
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