Skip to content

Commit

Permalink
Post without @RequestBody not getting all fields. Fixes #1455
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Jan 22, 2022
1 parent 240571e commit dff5873
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
}

if (!isParamToIgnore(methodParameter)) {
parameter = buildParams(parameterInfo, parameters.length, components, requestMethod, methodAttributes.getJsonViewAnnotation());
parameter = buildParams(parameterInfo, components, requestMethod, methodAttributes.getJsonViewAnnotation());
// Merge with the operation parameters
parameter = GenericParameterService.mergeParameter(operationParameters, parameter);
List<Annotation> parameterAnnotations = Arrays.asList(methodParameter.getParameterAnnotations());
Expand Down Expand Up @@ -434,13 +434,12 @@ public boolean isValidParameter(Parameter parameter) {
* Build params parameter.
*
* @param parameterInfo the parameter info
* @param length the length
* @param components the components
* @param requestMethod the request method
* @param jsonView the json view
* @return the parameter
*/
public Parameter buildParams(ParameterInfo parameterInfo, int length, Components components,
public Parameter buildParams(ParameterInfo parameterInfo, Components components,
RequestMethod requestMethod, JsonView jsonView) {
MethodParameter methodParameter = parameterInfo.getMethodParameter();
if (parameterInfo.getParamType() != null) {
Expand All @@ -451,7 +450,7 @@ public Parameter buildParams(ParameterInfo parameterInfo, int length, Components
return this.buildParam(parameterInfo, components, jsonView);
}
// By default
if (!isRequestBodyParam(requestMethod, parameterInfo, length)) {
if (!isRequestBodyParam(requestMethod, parameterInfo)) {
parameterInfo.setRequired(!((DelegatingMethodParameter) methodParameter).isNotRequired() && !methodParameter.isOptional());
parameterInfo.setParamType(QUERY_PARAM);
parameterInfo.setDefaultValue(null);
Expand Down Expand Up @@ -665,10 +664,9 @@ private void applyValidationsToSchema(Map<String, Annotation> annos, Schema<?> s
*
* @param requestMethod the request method
* @param parameterInfo the parameter info
* @param length the length
* @return the boolean
*/
private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo parameterInfo, int length) {
private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo parameterInfo) {
MethodParameter methodParameter = parameterInfo.getMethodParameter();
DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter) methodParameter;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ else if (methodParameter.getParameterAnnotation(BackendId.class) != null) {
parameterInfo.setParameterModel(parameter);
}
if (!ArrayUtils.isEmpty(methodParameter.getParameterAnnotations()))
parameter = requestBuilder.buildParams(parameterInfo, parameters.length, openAPI.getComponents(), requestMethod, null);
parameter = requestBuilder.buildParams(parameterInfo, openAPI.getComponents(), requestMethod, null);

addParameters(openAPI, requestMethod, methodAttributes, operation, methodParameter, parameterInfo, parameter);
}
Expand Down

0 comments on commit dff5873

Please sign in to comment.