Skip to content

Commit 4182ede

Browse files
author
bnasslahsen
committed
Map type with @RequestParam(required = false) in method isn't ignored. Fixes #553
1 parent 69bcdf4 commit 4182ede

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractRequestBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ protected Parameter customiseParameter(Parameter parameter, ParameterInfo parame
255255
protected boolean isParamToIgnore(MethodParameter parameter) {
256256
if (parameterBuilder.isAnnotationToIgnore(parameter))
257257
return true;
258-
if (parameter.getParameterAnnotation(PathVariable.class) != null || parameter.getParameterAnnotation(RequestParam.class) != null)
258+
if ((parameter.getParameterAnnotation(PathVariable.class) != null && parameter.getParameterAnnotation(PathVariable.class) .required()) || (parameter.getParameterAnnotation(RequestParam.class) != null && parameter.getParameterAnnotation(RequestParam.class).required()))
259259
return false;
260260
return isRequestTypeToIgnore(parameter.getParameterType());
261261
}

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app51/HelloController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919
package test.org.springdoc.api.app51;
2020

21+
import java.util.Map;
22+
2123
import io.swagger.v3.oas.annotations.Operation;
2224
import io.swagger.v3.oas.annotations.Parameter;
2325
import io.swagger.v3.oas.annotations.enums.ParameterIn;
2426
import io.swagger.v3.oas.annotations.media.Schema;
2527

2628
import org.springframework.web.bind.annotation.GetMapping;
29+
import org.springframework.web.bind.annotation.PathVariable;
2730
import org.springframework.web.bind.annotation.RequestParam;
2831
import org.springframework.web.bind.annotation.RestController;
2932

@@ -53,4 +56,11 @@ public String test3(
5356
return "test";
5457
}
5558

59+
@GetMapping("/test")
60+
public String get(
61+
@PathVariable String path,
62+
@RequestParam(required = false) Map<String, String> params) {
63+
return null;
64+
}
65+
5666
}

springdoc-openapi-webmvc-core/src/test/resources/results/app51.json

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,36 @@
1111
}
1212
],
1313
"paths": {
14+
"/test": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "get",
20+
"parameters": [
21+
{
22+
"name": "path",
23+
"in": "path",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "default response",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"type": "string"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
},
1444
"/test1": {
1545
"get": {
1646
"tags": [
@@ -42,12 +72,12 @@
4272
}
4373
}
4474
},
45-
"/test2": {
75+
"/test3": {
4676
"get": {
4777
"tags": [
4878
"hello-controller"
4979
],
50-
"operationId": "test2",
80+
"operationId": "test3",
5181
"parameters": [
5282
{
5383
"name": "test_header",
@@ -61,9 +91,11 @@
6191
{
6292
"name": "param1",
6393
"in": "query",
94+
"description": "desc1",
6495
"required": true,
6596
"schema": {
66-
"type": "string"
97+
"type": "string",
98+
"example": "something"
6799
}
68100
}
69101
],
@@ -81,12 +113,12 @@
81113
}
82114
}
83115
},
84-
"/test3": {
116+
"/test2": {
85117
"get": {
86118
"tags": [
87119
"hello-controller"
88120
],
89-
"operationId": "test3",
121+
"operationId": "test2",
90122
"parameters": [
91123
{
92124
"name": "test_header",
@@ -100,11 +132,9 @@
100132
{
101133
"name": "param1",
102134
"in": "query",
103-
"description": "desc1",
104135
"required": true,
105136
"schema": {
106-
"type": "string",
107-
"example": "something"
137+
"type": "string"
108138
}
109139
}
110140
],

0 commit comments

Comments
 (0)