2525package org .springdoc .core .service ;
2626
2727import java .lang .annotation .Annotation ;
28+ import java .lang .reflect .Field ;
2829import java .lang .reflect .Method ;
2930import java .math .BigDecimal ;
3031import java .util .ArrayList ;
8889import org .springframework .web .context .request .NativeWebRequest ;
8990import org .springframework .web .context .request .WebRequest ;
9091import org .springframework .web .method .HandlerMethod ;
92+ import org .springframework .web .multipart .MultipartFile ;
9193import org .springframework .web .util .UriComponentsBuilder ;
9294
9395import static org .springdoc .core .converters .SchemaPropertyDeprecatingConverter .containsDeprecatedAnnotation ;
9496import static org .springdoc .core .service .GenericParameterService .isFile ;
9597import static org .springdoc .core .utils .Constants .OPENAPI_ARRAY_TYPE ;
9698import static org .springdoc .core .utils .Constants .OPENAPI_STRING_TYPE ;
99+ import static org .springframework .http .MediaType .MULTIPART_FORM_DATA_VALUE ;
97100
98101/**
99102 * The type Abstract request builder.
@@ -323,7 +326,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
323326 }
324327
325328 if (!isParamToIgnore (methodParameter )) {
326- parameter = buildParams (parameterInfo , components , requestMethod , methodAttributes . getJsonViewAnnotation () , openAPI .getOpenapi ());
329+ parameter = buildParams (parameterInfo , components , requestMethod , methodAttributes , openAPI .getOpenapi ());
327330 // Merge with the operation parameters
328331 parameter = GenericParameterService .mergeParameter (operationParameters , parameter );
329332 List <Annotation > parameterAnnotations = Arrays .asList (methodParameter .getParameterAnnotations ());
@@ -353,7 +356,7 @@ else if (!RequestMethod.GET.equals(requestMethod) || OpenApiVersion.OPENAPI_3_1.
353356 // support form-data
354357 if (defaultSupportFormData && requestBody != null
355358 && requestBody .getContent () != null
356- && requestBody .getContent ().containsKey (org . springframework . http . MediaType . MULTIPART_FORM_DATA_VALUE )) {
359+ && requestBody .getContent ().containsKey (MULTIPART_FORM_DATA_VALUE )) {
357360 Iterator <Entry <ParameterId , Parameter >> it = map .entrySet ().iterator ();
358361 while (it .hasNext ()) {
359362 Entry <ParameterId , Parameter > entry = it .next ();
@@ -496,28 +499,28 @@ public boolean isValidParameter(Parameter parameter) {
496499 /**
497500 * Build params parameter.
498501 *
499- * @param parameterInfo the parameter info
500- * @param components the components
501- * @param requestMethod the request method
502- * @param jsonView the json view
503- * @param openApiVersion the open api version
502+ * @param parameterInfo the parameter info
503+ * @param components the components
504+ * @param requestMethod the request method
505+ * @param methodAttributes the method attributes
506+ * @param openApiVersion the open api version
504507 * @return the parameter
505508 */
506509 public Parameter buildParams (ParameterInfo parameterInfo , Components components ,
507- RequestMethod requestMethod , JsonView jsonView , String openApiVersion ) {
510+ RequestMethod requestMethod , MethodAttributes methodAttributes , String openApiVersion ) {
508511 MethodParameter methodParameter = parameterInfo .getMethodParameter ();
509512 if (parameterInfo .getParamType () != null ) {
510513 if (!ValueConstants .DEFAULT_NONE .equals (parameterInfo .getDefaultValue ()))
511514 parameterInfo .setRequired (false );
512515 else
513516 parameterInfo .setDefaultValue (null );
514- return this .buildParam (parameterInfo , components , jsonView );
517+ return this .buildParam (parameterInfo , components , methodAttributes . getJsonViewAnnotation () );
515518 }
516519 // By default
517- if (!isRequestBodyParam (requestMethod , parameterInfo , openApiVersion )) {
520+ if (!isRequestBodyParam (requestMethod , parameterInfo , openApiVersion , methodAttributes )) {
518521 parameterInfo .setRequired (!((DelegatingMethodParameter ) methodParameter ).isNotRequired () && !methodParameter .isOptional ());
519522 parameterInfo .setDefaultValue (null );
520- return this .buildParam (parameterInfo , components , jsonView );
523+ return this .buildParam (parameterInfo , components , methodAttributes . getJsonViewAnnotation () );
521524 }
522525 return null ;
523526 }
@@ -631,7 +634,7 @@ public RequestBodyService getRequestBodyBuilder() {
631634 public boolean isDefaultFlatParamObject () {
632635 return defaultFlatParamObject ;
633636 }
634-
637+
635638 /**
636639 * Calculate size.
637640 *
@@ -722,12 +725,13 @@ private void applyValidationsToSchema(Map<String, Annotation> annos, Schema<?> s
722725 /**
723726 * Is RequestBody param boolean.
724727 *
725- * @param requestMethod the request method
726- * @param parameterInfo the parameter info
727- * @param openApiVersion the open api version
728+ * @param requestMethod the request method
729+ * @param parameterInfo the parameter info
730+ * @param openApiVersion the open api version
731+ * @param methodAttributes the method attributes
728732 * @return the boolean
729733 */
730- private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo , String openApiVersion ) {
734+ private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo , String openApiVersion , MethodAttributes methodAttributes ) {
731735 MethodParameter methodParameter = parameterInfo .getMethodParameter ();
732736 DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter ) methodParameter ;
733737 boolean isBodyAllowed = !RequestMethod .GET .equals (requestMethod ) || OpenApiVersion .OPENAPI_3_1 .getVersion ().equals (openApiVersion );
@@ -739,8 +743,7 @@ private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo pa
739743 || AnnotatedElementUtils .findMergedAnnotation (Objects .requireNonNull (methodParameter .getMethod ()), io .swagger .v3 .oas .annotations .parameters .RequestBody .class ) != null )
740744 || checkOperationRequestBody (methodParameter )
741745 || checkFile (methodParameter )
742-
743- );
746+ || Arrays .asList (methodAttributes .getMethodConsumes ()).contains (MULTIPART_FORM_DATA_VALUE ));
744747 }
745748
746749 /**
@@ -767,7 +770,7 @@ else if (methodParameter.getParameterAnnotation(org.springframework.web.bind.ann
767770 private boolean checkOperationRequestBody (MethodParameter methodParameter ) {
768771 if (AnnotatedElementUtils .findMergedAnnotation (Objects .requireNonNull (methodParameter .getMethod ()), io .swagger .v3 .oas .annotations .Operation .class ) != null ) {
769772 io .swagger .v3 .oas .annotations .Operation operation = AnnotatedElementUtils .findMergedAnnotation (Objects .requireNonNull (methodParameter .getMethod ()), io .swagger .v3 .oas .annotations .Operation .class );
770- if (operation != null ){
773+ if (operation != null ) {
771774 io .swagger .v3 .oas .annotations .parameters .RequestBody requestBody = operation .requestBody ();
772775 if (StringUtils .isNotBlank (requestBody .description ()))
773776 return true ;
0 commit comments