This repository has been archived by the owner on Nov 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
706dc2b
commit d8106f4
Showing
5 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...main/kotlin/ru/sokomishalov/commons/spring/swagger/KotlinFriendlyHandlerMethodResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", "[email protected]") | ||
private val TYPE_RESOLVER = TypeResolver() | ||
|
||
inline fun <reified T : Any> initDocket(): Docket { | ||
return Docket(SWAGGER_2) | ||
inline fun <reified T : Any> 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 <reified T : Any> initDocket(): Docket { | |
fun Docket.customize( | ||
securityContext: SecurityContext? = null, | ||
securityScheme: SecurityScheme? = null, | ||
ignoredParameterTypes: List<Class<out Any>> = listOf(ServerHttpRequest::class.java, Continuation::class.java), | ||
genericModelSubstitutes: List<Class<out Any>> = listOf(ResponseEntity::class.java, CompletableFuture::class.java), | ||
ignoredParameterTypes: List<Class<out Any>> = emptyList(), | ||
genericModelSubstitutes: List<Class<out Any>> = listOf(ResponseEntity::class.java, CompletableFuture::class.java, Future::class.java), | ||
useDefaultResponseMessages: Boolean = false, | ||
buildProperties: BuildProperties? = null, | ||
title: String = buildProperties?.name.orEmpty(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters