25
25
package org .springdoc .core .service ;
26
26
27
27
import java .lang .annotation .Annotation ;
28
+ import java .lang .reflect .Field ;
28
29
import java .lang .reflect .Method ;
29
30
import java .math .BigDecimal ;
30
31
import java .util .ArrayList ;
88
89
import org .springframework .web .context .request .NativeWebRequest ;
89
90
import org .springframework .web .context .request .WebRequest ;
90
91
import org .springframework .web .method .HandlerMethod ;
92
+ import org .springframework .web .multipart .MultipartFile ;
91
93
import org .springframework .web .util .UriComponentsBuilder ;
92
94
93
95
import static org .springdoc .core .converters .SchemaPropertyDeprecatingConverter .containsDeprecatedAnnotation ;
94
96
import static org .springdoc .core .service .GenericParameterService .isFile ;
95
97
import static org .springdoc .core .utils .Constants .OPENAPI_ARRAY_TYPE ;
96
98
import static org .springdoc .core .utils .Constants .OPENAPI_STRING_TYPE ;
99
+ import static org .springframework .http .MediaType .MULTIPART_FORM_DATA_VALUE ;
97
100
98
101
/**
99
102
* The type Abstract request builder.
@@ -323,7 +326,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
323
326
}
324
327
325
328
if (!isParamToIgnore (methodParameter )) {
326
- parameter = buildParams (parameterInfo , components , requestMethod , methodAttributes . getJsonViewAnnotation () , openAPI .getOpenapi ());
329
+ parameter = buildParams (parameterInfo , components , requestMethod , methodAttributes , openAPI .getOpenapi ());
327
330
// Merge with the operation parameters
328
331
parameter = GenericParameterService .mergeParameter (operationParameters , parameter );
329
332
List <Annotation > parameterAnnotations = Arrays .asList (methodParameter .getParameterAnnotations ());
@@ -353,7 +356,7 @@ else if (!RequestMethod.GET.equals(requestMethod) || OpenApiVersion.OPENAPI_3_1.
353
356
// support form-data
354
357
if (defaultSupportFormData && requestBody != null
355
358
&& requestBody .getContent () != null
356
- && requestBody .getContent ().containsKey (org . springframework . http . MediaType . MULTIPART_FORM_DATA_VALUE )) {
359
+ && requestBody .getContent ().containsKey (MULTIPART_FORM_DATA_VALUE )) {
357
360
Iterator <Entry <ParameterId , Parameter >> it = map .entrySet ().iterator ();
358
361
while (it .hasNext ()) {
359
362
Entry <ParameterId , Parameter > entry = it .next ();
@@ -496,28 +499,28 @@ public boolean isValidParameter(Parameter parameter) {
496
499
/**
497
500
* Build params parameter.
498
501
*
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
504
507
* @return the parameter
505
508
*/
506
509
public Parameter buildParams (ParameterInfo parameterInfo , Components components ,
507
- RequestMethod requestMethod , JsonView jsonView , String openApiVersion ) {
510
+ RequestMethod requestMethod , MethodAttributes methodAttributes , String openApiVersion ) {
508
511
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
509
512
if (parameterInfo .getParamType () != null ) {
510
513
if (!ValueConstants .DEFAULT_NONE .equals (parameterInfo .getDefaultValue ()))
511
514
parameterInfo .setRequired (false );
512
515
else
513
516
parameterInfo .setDefaultValue (null );
514
- return this .buildParam (parameterInfo , components , jsonView );
517
+ return this .buildParam (parameterInfo , components , methodAttributes . getJsonViewAnnotation () );
515
518
}
516
519
// By default
517
- if (!isRequestBodyParam (requestMethod , parameterInfo , openApiVersion )) {
520
+ if (!isRequestBodyParam (requestMethod , parameterInfo , openApiVersion , methodAttributes )) {
518
521
parameterInfo .setRequired (!((DelegatingMethodParameter ) methodParameter ).isNotRequired () && !methodParameter .isOptional ());
519
522
parameterInfo .setDefaultValue (null );
520
- return this .buildParam (parameterInfo , components , jsonView );
523
+ return this .buildParam (parameterInfo , components , methodAttributes . getJsonViewAnnotation () );
521
524
}
522
525
return null ;
523
526
}
@@ -631,7 +634,7 @@ public RequestBodyService getRequestBodyBuilder() {
631
634
public boolean isDefaultFlatParamObject () {
632
635
return defaultFlatParamObject ;
633
636
}
634
-
637
+
635
638
/**
636
639
* Calculate size.
637
640
*
@@ -722,12 +725,13 @@ private void applyValidationsToSchema(Map<String, Annotation> annos, Schema<?> s
722
725
/**
723
726
* Is RequestBody param boolean.
724
727
*
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
728
732
* @return the boolean
729
733
*/
730
- private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo , String openApiVersion ) {
734
+ private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo , String openApiVersion , MethodAttributes methodAttributes ) {
731
735
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
732
736
DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter ) methodParameter ;
733
737
boolean isBodyAllowed = !RequestMethod .GET .equals (requestMethod ) || OpenApiVersion .OPENAPI_3_1 .getVersion ().equals (openApiVersion );
@@ -739,8 +743,7 @@ private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo pa
739
743
|| AnnotatedElementUtils .findMergedAnnotation (Objects .requireNonNull (methodParameter .getMethod ()), io .swagger .v3 .oas .annotations .parameters .RequestBody .class ) != null )
740
744
|| checkOperationRequestBody (methodParameter )
741
745
|| checkFile (methodParameter )
742
-
743
- );
746
+ || Arrays .asList (methodAttributes .getMethodConsumes ()).contains (MULTIPART_FORM_DATA_VALUE ));
744
747
}
745
748
746
749
/**
@@ -767,7 +770,7 @@ else if (methodParameter.getParameterAnnotation(org.springframework.web.bind.ann
767
770
private boolean checkOperationRequestBody (MethodParameter methodParameter ) {
768
771
if (AnnotatedElementUtils .findMergedAnnotation (Objects .requireNonNull (methodParameter .getMethod ()), io .swagger .v3 .oas .annotations .Operation .class ) != null ) {
769
772
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 ) {
771
774
io .swagger .v3 .oas .annotations .parameters .RequestBody requestBody = operation .requestBody ();
772
775
if (StringUtils .isNotBlank (requestBody .description ()))
773
776
return true ;
0 commit comments