Skip to content

Commit 950669a

Browse files
author
bnasslahsen
committed
Added support for @JsonViews with spring @RequestBody annotation. Fixes #315
1 parent 160f773 commit 950669a

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.springframework.core.annotation.AnnotationUtils;
1515
import org.springframework.util.AntPathMatcher;
1616
import org.springframework.util.CollectionUtils;
17+
import org.springframework.web.bind.annotation.RequestBody;
1718
import org.springframework.web.bind.annotation.RequestMapping;
1819
import org.springframework.web.bind.annotation.RequestMethod;
1920
import org.springframework.web.method.HandlerMethod;
@@ -200,8 +201,8 @@ private void calculateJsonView(io.swagger.v3.oas.annotations.Operation apiOperat
200201
*/
201202
jsonViewAnnotationForRequestBody = (JsonView) Arrays.stream(ReflectionUtils.getParameterAnnotations(method))
202203
.filter(arr -> Arrays.stream(arr)
203-
.anyMatch(annotation -> annotation.annotationType()
204-
.equals(io.swagger.v3.oas.annotations.parameters.RequestBody.class)))
204+
.anyMatch(annotation -> (annotation.annotationType()
205+
.equals(io.swagger.v3.oas.annotations.parameters.RequestBody.class) || annotation.annotationType().equals(RequestBody.class))))
205206
.flatMap(Arrays::stream).filter(annotation -> annotation.annotationType().equals(JsonView.class))
206207
.reduce((a, b) -> null).orElse(jsonViewAnnotation);
207208
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public ResponseEntity<MealParty> saveMealParty(@JsonView(Views.Public.class) @Re
2828
return null;
2929
}
3030

31+
@JsonView(Views.MealPartyAdmin.class)
32+
@PostMapping(value = "/new-parties")
33+
public ResponseEntity<MealParty> saveMealNewParty(@JsonView(Views.Public.class) @org.springframework.web.bind.annotation.RequestBody MealParty p) {
34+
return null;
35+
}
3136
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@
7171
}
7272
}
7373
}
74+
},
75+
"/new-parties": {
76+
"post": {
77+
"tags": [
78+
"hello-controller"
79+
],
80+
"operationId": "saveMealNewParty",
81+
"requestBody": {
82+
"content": {
83+
"application/json": {
84+
"schema": {
85+
"$ref": "#/components/schemas/MealParty_Public"
86+
}
87+
}
88+
}
89+
},
90+
"responses": {
91+
"200": {
92+
"description": "default response",
93+
"content": {
94+
"*/*": {
95+
"schema": {
96+
"$ref": "#/components/schemas/MealParty_MealPartyAdmin"
97+
}
98+
}
99+
}
100+
}
101+
}
102+
}
74103
}
75104
},
76105
"components": {

0 commit comments

Comments
 (0)