diff --git a/README.md b/README.md index 7abee66..75053be 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Add the dependency: com.github.sokomishalov.commons commons-[module] - 1.1.18 + 1.1.19 ``` diff --git a/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/serialization/SerializationUtils.kt b/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/serialization/SerializationUtils.kt index d37a501..c1b29bd 100644 --- a/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/serialization/SerializationUtils.kt +++ b/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/serialization/SerializationUtils.kt @@ -25,8 +25,5 @@ import ru.sokomishalov.commons.core.serialization.OBJECT_MAPPER * @author sokomishalov */ - val JACKSON_ENCODER = Jackson2JsonEncoder(OBJECT_MAPPER) - - val JACKSON_DECODER = Jackson2JsonDecoder(OBJECT_MAPPER) \ No newline at end of file diff --git a/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/swagger/KotlinFriendlyHandlerMethodResolver.kt b/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/swagger/KotlinFriendlyHandlerMethodResolver.kt new file mode 100644 index 0000000..6a4c46c --- /dev/null +++ b/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/swagger/KotlinFriendlyHandlerMethodResolver.kt @@ -0,0 +1,24 @@ +package ru.sokomishalov.commons.spring.swagger + +import com.fasterxml.classmate.ResolvedType +import com.fasterxml.classmate.TypeResolver +import org.springframework.web.method.HandlerMethod +import springfox.documentation.spring.web.readers.operation.HandlerMethodResolver +import kotlin.reflect.jvm.javaType +import kotlin.reflect.jvm.kotlinFunction + +/** + * @author sokomishalov + */ +class KotlinFriendlyHandlerMethodResolver( + private val typeResolver: TypeResolver +) : HandlerMethodResolver(typeResolver) { + + override fun methodReturnType(handlerMethod: HandlerMethod?): ResolvedType { + val kFunction = handlerMethod?.method?.kotlinFunction + return when { + kFunction != null -> typeResolver.resolve(kFunction.returnType.javaType) + else -> super.methodReturnType(handlerMethod) + } + } +} \ No newline at end of file diff --git a/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/swagger/SwaggerUtils.kt b/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/swagger/SwaggerUtils.kt index d795378..f8a5f98 100644 --- a/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/swagger/SwaggerUtils.kt +++ b/commons-spring/src/main/kotlin/ru/sokomishalov/commons/spring/swagger/SwaggerUtils.kt @@ -21,7 +21,6 @@ import com.fasterxml.classmate.TypeResolver import org.springframework.boot.info.BuildProperties import org.springframework.http.ResponseEntity import org.springframework.http.codec.multipart.FilePart -import org.springframework.http.server.reactive.ServerHttpRequest import org.springframework.web.multipart.MultipartFile import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -30,11 +29,12 @@ import springfox.documentation.builders.RequestHandlerSelectors.basePackage import springfox.documentation.schema.AlternateTypeRules.newRule import springfox.documentation.service.Contact import springfox.documentation.service.SecurityScheme -import springfox.documentation.spi.DocumentationType.SWAGGER_2 +import springfox.documentation.spi.DocumentationType +import springfox.documentation.spi.DocumentationType.OAS_30 import springfox.documentation.spi.service.contexts.SecurityContext import springfox.documentation.spring.web.plugins.Docket import java.util.concurrent.CompletableFuture -import kotlin.coroutines.Continuation +import java.util.concurrent.Future /** * @author sokomishalov @@ -45,8 +45,8 @@ const val REDIRECT_TO_SWAGGER = "redirect:${SWAGGER_UI_PAGE}" private val DEFAULT_AUTHOR = Contact("Sokolov Mikhael", "https://sokomishalov.github.io/about-me", "sokomishalov@mail.ru") private val TYPE_RESOLVER = TypeResolver() -inline fun initDocket(): Docket { - return Docket(SWAGGER_2) +inline fun initDocket(type: DocumentationType = OAS_30): Docket { + return Docket(type) .select() .apis(basePackage(T::class.java.`package`.name)) .paths { true } @@ -56,8 +56,8 @@ inline fun initDocket(): Docket { fun Docket.customize( securityContext: SecurityContext? = null, securityScheme: SecurityScheme? = null, - ignoredParameterTypes: List> = listOf(ServerHttpRequest::class.java, Continuation::class.java), - genericModelSubstitutes: List> = listOf(ResponseEntity::class.java, CompletableFuture::class.java), + ignoredParameterTypes: List> = emptyList(), + genericModelSubstitutes: List> = listOf(ResponseEntity::class.java, CompletableFuture::class.java, Future::class.java), useDefaultResponseMessages: Boolean = false, buildProperties: BuildProperties? = null, title: String = buildProperties?.name.orEmpty(), diff --git a/pom.xml b/pom.xml index 0a0ac79..4e9fcbb 100644 --- a/pom.xml +++ b/pom.xml @@ -10,19 +10,19 @@ pom - 1.1.18 + 1.1.19 1.8 1.3.72 - 1.3.7 + 1.3.8 2.11.1 - 3.3.7.RELEASE - 0.9.9.RELEASE + 3.3.8.RELEASE + 0.9.10.RELEASE 4.0.1 1.7.30 1.2.3 - 2.3.1.RELEASE - 5.2.7.RELEASE + 2.3.2.RELEASE + 5.2.8.RELEASE 3.0.0