@@ -14,6 +14,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
1414import org.springframework.context.annotation.Bean
1515import org.springframework.context.annotation.Configuration
1616import org.springframework.context.annotation.Lazy
17+ import org.springframework.core.KotlinDetector
1718import org.springframework.core.MethodParameter
1819import org.springframework.core.annotation.AnnotatedElementUtils
1920import org.springframework.web.bind.annotation.RequestParam
@@ -71,27 +72,30 @@ class SpringDocKotlinConfiguration(objectMapperProvider: ObjectMapperProvider) {
7172 matchIfMissing = true
7273 )
7374 @ConditionalOnMissingBean
74- fun nullableKotlinRequestParameterCustomizer (): ParameterCustomizer {
75+ open fun nullableKotlinRequestParameterCustomizer (): ParameterCustomizer {
7576 return ParameterCustomizer { parameterModel, methodParameter ->
7677 if (parameterModel == null ) return @ParameterCustomizer null
77- val kParameter = methodParameter.toKParameter()
78- if (kParameter != null ) {
79- val parameterDoc = AnnotatedElementUtils .findMergedAnnotation(
80- AnnotatedElementUtils .forAnnotations(* methodParameter.parameterAnnotations),
81- Parameter ::class .java
82- )
83- val requestParam = AnnotatedElementUtils .findMergedAnnotation(
78+ if (KotlinDetector .isKotlinType(methodParameter.parameterType)) {
79+ val kParameter = methodParameter.toKParameter()
80+ if (kParameter != null ) {
81+ val parameterDoc = AnnotatedElementUtils .findMergedAnnotation(
82+ AnnotatedElementUtils .forAnnotations(* methodParameter.parameterAnnotations),
83+ Parameter ::class .java
84+ )
85+ val requestParam = AnnotatedElementUtils .findMergedAnnotation(
8486 AnnotatedElementUtils .forAnnotations(* methodParameter.parameterAnnotations),
8587 RequestParam ::class .java
86- )
87- // Swagger @Parameter annotation takes precedence
88- if (parameterDoc != null && parameterDoc.required)
89- parameterModel.required = parameterDoc.required
90- // parameter is not required if a default value is provided in @RequestParam
91- else if (requestParam != null && ((requestParam.defaultValue != ValueConstants .DEFAULT_NONE ) || ! requestParam.required))
92- parameterModel.required = false
93- else
94- parameterModel.required = kParameter.type.isMarkedNullable == false
88+ )
89+ // Swagger @Parameter annotation takes precedence
90+ if (parameterDoc != null && parameterDoc.required)
91+ parameterModel.required = parameterDoc.required
92+ // parameter is not required if a default value is provided in @RequestParam
93+ else if (requestParam != null && requestParam.defaultValue != ValueConstants .DEFAULT_NONE )
94+ parameterModel.required = false
95+ else
96+ parameterModel.required =
97+ kParameter.type.isMarkedNullable == false
98+ }
9599 }
96100 return @ParameterCustomizer parameterModel
97101 }
0 commit comments