Skip to content

Commit

Permalink
All request headers marked as required for Java controllers in mixed …
Browse files Browse the repository at this point in the history
…projects in 2.0.3. fixes #2187
  • Loading branch information
bnasslahsen committed Apr 1, 2023
1 parent bd08fb3 commit 9e3101b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ open class SpringDocKotlinConfiguration(objectMapperProvider: ObjectMapperProvid
open fun nullableKotlinRequestParameterCustomizer(): ParameterCustomizer {
return ParameterCustomizer { parameterModel, methodParameter ->
if (parameterModel == null) return@ParameterCustomizer null
if (KotlinDetector.isKotlinReflectPresent()) {
if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(methodParameter.parameterType)) {
val kParameter = methodParameter.toKParameter()
if (kParameter != null) {
val parameterDoc = AnnotatedElementUtils.findMergedAnnotation(
Expand All @@ -99,7 +99,7 @@ open class SpringDocKotlinConfiguration(objectMapperProvider: ObjectMapperProvid
if (parameterDoc != null && parameterDoc.required)
parameterModel.required = parameterDoc.required
// parameter is not required if a default value is provided in @RequestParam
else if (requestParam != null && ((requestParam.defaultValue != ValueConstants.DEFAULT_NONE) || !requestParam.required))
else if (requestParam != null && requestParam.defaultValue != ValueConstants.DEFAULT_NONE)
parameterModel.required = false
else
parameterModel.required =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -17,4 +18,8 @@ public class HelloController {
@GetMapping("/")
public void greet(@RequestParam(required = false) @Parameter(required = false) final String name) {
}

@GetMapping("/test2")
public void greet1(@RequestHeader(required = false) @Parameter(required = false) final String name) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@
}
],
"paths": {
"/api/v2/test/test2": {
"get": {
"tags": [
"Test"
],
"operationId": "greet1",
"parameters": [
{
"name": "name",
"in": "header",
"required": false,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v2/test/": {
"get": {
"tags": [
Expand Down

0 comments on commit 9e3101b

Please sign in to comment.