Skip to content

Commit dff5873

Browse files
committed
Post without @RequestBody not getting all fields. Fixes #1455
1 parent 240571e commit dff5873

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
264264
}
265265

266266
if (!isParamToIgnore(methodParameter)) {
267-
parameter = buildParams(parameterInfo, parameters.length, components, requestMethod, methodAttributes.getJsonViewAnnotation());
267+
parameter = buildParams(parameterInfo, components, requestMethod, methodAttributes.getJsonViewAnnotation());
268268
// Merge with the operation parameters
269269
parameter = GenericParameterService.mergeParameter(operationParameters, parameter);
270270
List<Annotation> parameterAnnotations = Arrays.asList(methodParameter.getParameterAnnotations());
@@ -434,13 +434,12 @@ public boolean isValidParameter(Parameter parameter) {
434434
* Build params parameter.
435435
*
436436
* @param parameterInfo the parameter info
437-
* @param length the length
438437
* @param components the components
439438
* @param requestMethod the request method
440439
* @param jsonView the json view
441440
* @return the parameter
442441
*/
443-
public Parameter buildParams(ParameterInfo parameterInfo, int length, Components components,
442+
public Parameter buildParams(ParameterInfo parameterInfo, Components components,
444443
RequestMethod requestMethod, JsonView jsonView) {
445444
MethodParameter methodParameter = parameterInfo.getMethodParameter();
446445
if (parameterInfo.getParamType() != null) {
@@ -451,7 +450,7 @@ public Parameter buildParams(ParameterInfo parameterInfo, int length, Components
451450
return this.buildParam(parameterInfo, components, jsonView);
452451
}
453452
// By default
454-
if (!isRequestBodyParam(requestMethod, parameterInfo, length)) {
453+
if (!isRequestBodyParam(requestMethod, parameterInfo)) {
455454
parameterInfo.setRequired(!((DelegatingMethodParameter) methodParameter).isNotRequired() && !methodParameter.isOptional());
456455
parameterInfo.setParamType(QUERY_PARAM);
457456
parameterInfo.setDefaultValue(null);
@@ -665,10 +664,9 @@ private void applyValidationsToSchema(Map<String, Annotation> annos, Schema<?> s
665664
*
666665
* @param requestMethod the request method
667666
* @param parameterInfo the parameter info
668-
* @param length the length
669667
* @return the boolean
670668
*/
671-
private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo parameterInfo, int length) {
669+
private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo parameterInfo) {
672670
MethodParameter methodParameter = parameterInfo.getMethodParameter();
673671
DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter) methodParameter;
674672

@@ -677,7 +675,7 @@ private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo pa
677675
((methodParameter.getParameterAnnotation(io.swagger.v3.oas.annotations.parameters.RequestBody.class) != null
678676
|| methodParameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestBody.class) != null
679677
|| methodParameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestPart.class) != null
680-
|| methodParameter.getMethod().getAnnotation(io.swagger.v3.oas.annotations.parameters.RequestBody.class) !=null)
678+
|| AnnotatedElementUtils.findMergedAnnotation(Objects.requireNonNull(methodParameter.getMethod()), io.swagger.v3.oas.annotations.parameters.RequestBody.class) != null)
681679
|| (!ClassUtils.isPrimitiveOrWrapper(methodParameter.getParameterType()) && (!ArrayUtils.isEmpty(methodParameter.getParameterAnnotations()))));
682680
}
683681

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/core/DataRestRequestService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ else if (methodParameter.getParameterAnnotation(BackendId.class) != null) {
174174
parameterInfo.setParameterModel(parameter);
175175
}
176176
if (!ArrayUtils.isEmpty(methodParameter.getParameterAnnotations()))
177-
parameter = requestBuilder.buildParams(parameterInfo, parameters.length, openAPI.getComponents(), requestMethod, null);
177+
parameter = requestBuilder.buildParams(parameterInfo, openAPI.getComponents(), requestMethod, null);
178178

179179
addParameters(openAPI, requestMethod, methodAttributes, operation, methodParameter, parameterInfo, parameter);
180180
}

0 commit comments

Comments
 (0)