Skip to content

Commit 48d9a8a

Browse files
author
bnasslahsen
committed
Request Body for Maps not available in Swagger-UI. Fixes #597
1 parent 9b0056a commit 48d9a8a

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ 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(PathVariable.class) .required()) || (parameter.getParameterAnnotation(RequestParam.class) != null && parameter.getParameterAnnotation(RequestParam.class).required()))
258+
if ((parameter.getParameterAnnotation(PathVariable.class) != null && parameter.getParameterAnnotation(PathVariable.class) .required())
259+
|| (parameter.getParameterAnnotation(RequestParam.class) != null && parameter.getParameterAnnotation(RequestParam.class).required())
260+
|| (parameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestBody.class) != null && parameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestBody.class).required()))
259261
return false;
260262
return isRequestTypeToIgnore(parameter.getParameterType());
261263
}

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

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

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

21+
import java.util.HashMap;
2122
import java.util.Map;
2223

2324
import io.swagger.v3.oas.annotations.Operation;
2425
import io.swagger.v3.oas.annotations.Parameter;
2526
import io.swagger.v3.oas.annotations.enums.ParameterIn;
2627
import io.swagger.v3.oas.annotations.media.Schema;
2728

29+
import org.springframework.http.ResponseEntity;
2830
import org.springframework.web.bind.annotation.GetMapping;
2931
import org.springframework.web.bind.annotation.PathVariable;
32+
import org.springframework.web.bind.annotation.PostMapping;
33+
import org.springframework.web.bind.annotation.RequestBody;
3034
import org.springframework.web.bind.annotation.RequestParam;
3135
import org.springframework.web.bind.annotation.RestController;
3236

@@ -63,4 +67,8 @@ public String get(
6367
return null;
6468
}
6569

70+
@PostMapping
71+
public ResponseEntity<HashMap<String, Object>> hello(@RequestBody HashMap<String, Object> map) {
72+
return ResponseEntity.ok(map);
73+
}
6674
}

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

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
}
4242
}
4343
},
44-
"/test1": {
44+
"/test2": {
4545
"get": {
4646
"tags": [
4747
"hello-controller"
4848
],
49-
"operationId": "test1",
49+
"operationId": "test2",
5050
"parameters": [
5151
{
5252
"name": "test_header",
@@ -56,6 +56,14 @@
5656
"type": "string",
5757
"example": "rherherherherh"
5858
}
59+
},
60+
{
61+
"name": "param1",
62+
"in": "query",
63+
"required": true,
64+
"schema": {
65+
"type": "string"
66+
}
5967
}
6068
],
6169
"responses": {
@@ -113,12 +121,12 @@
113121
}
114122
}
115123
},
116-
"/test2": {
124+
"/test1": {
117125
"get": {
118126
"tags": [
119127
"hello-controller"
120128
],
121-
"operationId": "test2",
129+
"operationId": "test1",
122130
"parameters": [
123131
{
124132
"name": "test_header",
@@ -128,14 +136,6 @@
128136
"type": "string",
129137
"example": "rherherherherh"
130138
}
131-
},
132-
{
133-
"name": "param1",
134-
"in": "query",
135-
"required": true,
136-
"schema": {
137-
"type": "string"
138-
}
139139
}
140140
],
141141
"responses": {
@@ -151,6 +151,42 @@
151151
}
152152
}
153153
}
154+
},
155+
"/": {
156+
"post": {
157+
"tags": [
158+
"hello-controller"
159+
],
160+
"operationId": "hello",
161+
"requestBody": {
162+
"content": {
163+
"application/json": {
164+
"schema": {
165+
"type": "object",
166+
"additionalProperties": {
167+
"type": "object"
168+
}
169+
}
170+
}
171+
},
172+
"required": true
173+
},
174+
"responses": {
175+
"200": {
176+
"description": "default response",
177+
"content": {
178+
"*/*": {
179+
"schema": {
180+
"type": "object",
181+
"additionalProperties": {
182+
"type": "object"
183+
}
184+
}
185+
}
186+
}
187+
}
188+
}
189+
}
154190
}
155191
},
156192
"components": {}

0 commit comments

Comments
 (0)