Updated annotation and add openapi, node, health for spring boot template

This commit is contained in:
Sambo Chea 2022-04-11 09:03:04 +07:00
parent e1c4b424cd
commit e0f3ab1889
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
9 changed files with 64 additions and 4 deletions

View File

@ -1,6 +1,6 @@
package com.cubetiqs.web
import com.cubetiqs.web.stereotype.FunctionComponent
import com.cubetiqs.web.annotation.FunctionComponent
import org.springframework.context.annotation.Lazy
@FunctionComponent

View File

@ -0,0 +1,7 @@
package com.cubetiqs.web.annotation
import org.springdoc.core.converters.models.PageableAsQueryParam
@Retention(AnnotationRetention.RUNTIME)
@PageableAsQueryParam
annotation class ApiPageableAsQuery()

View File

@ -0,0 +1,7 @@
package com.cubetiqs.web.annotation
import io.swagger.v3.oas.annotations.Parameter
@Retention(AnnotationRetention.RUNTIME)
@Parameter(hidden = true)
annotation class ApiParamHidden()

View File

@ -1,4 +1,4 @@
package com.cubetiqs.web.stereotype
package com.cubetiqs.web.annotation
import org.springframework.context.annotation.Lazy
import org.springframework.core.annotation.AliasFor

View File

@ -12,6 +12,9 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import io.swagger.v3.oas.annotations.OpenAPIDefinition
import io.swagger.v3.oas.annotations.servers.Server
//import org.springdoc.core.SpringDocUtils
//import org.springdoc.core.converters.models.Pageable
//import javax.servlet.http.HttpServletRequest
@Configuration
@SecurityScheme(
@ -33,6 +36,20 @@ class OpenApiDocConfig @Autowired constructor(
private val DEFAULT_API_PATH get() = "/**"
}
// init {
// SpringDocUtils.getConfig()
// .replaceParameterObjectWithClass(org.springframework.data.domain.Pageable::class.java, Pageable::class.java)
// .replaceParameterObjectWithClass(
// org.springframework.data.domain.PageRequest::class.java,
// Pageable::class.java
// )
// .removeRequestWrapperToIgnore(
// HttpServletRequest::class.java,
// org.springframework.data.domain.Pageable::class.java,
// org.springframework.data.domain.PageRequest::class.java,
// )
// }
@Bean
fun defaultApi(): GroupedOpenApi {
return GroupedOpenApi.builder()

View File

@ -3,6 +3,7 @@ package com.cubetiqs.web.controller
import com.cubetiqs.web.model.response.ApiInfoAuthorResponse
import com.cubetiqs.web.model.response.ApiInfoResponse
import com.cubetiqs.web.model.response.HealthResponse
import com.cubetiqs.web.model.response.NodeInfoResponse
import com.cubetiqs.web.util.RouteConstants
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.beans.factory.annotation.Autowired
@ -44,4 +45,11 @@ class IndexController @Autowired constructor(
HealthResponse.UP
)
}
@GetMapping("/node")
fun node(): ResponseEntity<NodeInfoResponse?> {
return response(
NodeInfoResponse.INFO
)
}
}

View File

@ -0,0 +1,21 @@
package com.cubetiqs.web.model.response
import io.swagger.v3.oas.annotations.media.Schema
import org.apache.commons.lang3.SystemUtils
import java.util.*
@Schema(name = "NodeInfoResponse", description = "Node Info Response")
data class NodeInfoResponse(
@Schema(name = "instance", description = "Instance ID of the node")
val instance: String?,
@Schema(name = "serverTime", description = "Server Time of the node")
val serverTime: Date,
) : BaseRequestModel {
companion object {
val INFO get() = NodeInfoResponse(
instance = SystemUtils.getHostName(),
serverTime = Date(),
)
}
}

View File

@ -1,6 +1,6 @@
package com.cubetiqs.web.property
import com.cubetiqs.web.stereotype.FunctionComponent
import com.cubetiqs.web.annotation.FunctionComponent
import org.springframework.beans.factory.annotation.Value
@FunctionComponent