64
64
import org .apache .commons .lang3 .ArrayUtils ;
65
65
import org .apache .commons .lang3 .StringUtils ;
66
66
import org .apache .commons .lang3 .reflect .FieldUtils ;
67
+ import org .springdoc .core .SpringDocConfigProperties .ApiDocs .OpenApiVersion ;
67
68
import org .springdoc .core .customizers .ParameterCustomizer ;
68
69
import org .springdoc .core .providers .JavadocProvider ;
69
70
@@ -291,7 +292,8 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
291
292
}
292
293
293
294
if (!isParamToIgnore (methodParameter )) {
294
- parameter = buildParams (parameterInfo , components , requestMethod , methodAttributes .getJsonViewAnnotation ());
295
+ parameter = buildParams (parameterInfo , components , requestMethod , methodAttributes .getJsonViewAnnotation (),
296
+ openAPI .getOpenapi ());
295
297
// Merge with the operation parameters
296
298
parameter = GenericParameterService .mergeParameter (operationParameters , parameter );
297
299
List <Annotation > parameterAnnotations = Arrays .asList (methodParameter .getParameterAnnotations ());
@@ -305,7 +307,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
305
307
}
306
308
applyBeanValidatorAnnotations (parameter , parameterAnnotations );
307
309
}
308
- else if (!RequestMethod .GET .equals (requestMethod )) {
310
+ else if (!RequestMethod .GET .equals (requestMethod ) || OpenApiVersion . OPENAPI_3_1 . getVersion (). equals ( openAPI . getOpenapi ()) ) {
309
311
if (operation .getRequestBody () != null )
310
312
requestBodyInfo .setRequestBody (operation .getRequestBody ());
311
313
requestBodyService .calculateRequestBodyInfo (components , methodAttributes ,
@@ -488,10 +490,11 @@ public boolean isValidParameter(Parameter parameter) {
488
490
* @param components the components
489
491
* @param requestMethod the request method
490
492
* @param jsonView the json view
493
+ * @param openApiVersion the open api version
491
494
* @return the parameter
492
495
*/
493
496
public Parameter buildParams (ParameterInfo parameterInfo , Components components ,
494
- RequestMethod requestMethod , JsonView jsonView ) {
497
+ RequestMethod requestMethod , JsonView jsonView , String openApiVersion ) {
495
498
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
496
499
if (parameterInfo .getParamType () != null ) {
497
500
if (!ValueConstants .DEFAULT_NONE .equals (parameterInfo .getDefaultValue ()))
@@ -501,7 +504,7 @@ public Parameter buildParams(ParameterInfo parameterInfo, Components components,
501
504
return this .buildParam (parameterInfo , components , jsonView );
502
505
}
503
506
// By default
504
- if (!isRequestBodyParam (requestMethod , parameterInfo )) {
507
+ if (!isRequestBodyParam (requestMethod , parameterInfo , openApiVersion )) {
505
508
parameterInfo .setRequired (!((DelegatingMethodParameter ) methodParameter ).isNotRequired () && !methodParameter .isOptional ());
506
509
parameterInfo .setParamType (QUERY_PARAM );
507
510
parameterInfo .setDefaultValue (null );
@@ -715,13 +718,15 @@ private void applyValidationsToSchema(Map<String, Annotation> annos, Schema<?> s
715
718
*
716
719
* @param requestMethod the request method
717
720
* @param parameterInfo the parameter info
721
+ * @param openApiVersion the open api version
718
722
* @return the boolean
719
723
*/
720
- private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo ) {
724
+ private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo , String openApiVersion ) {
721
725
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
722
726
DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter ) methodParameter ;
727
+ Boolean isBodyAllowed = !RequestMethod .GET .equals (requestMethod ) || OpenApiVersion .OPENAPI_3_1 .getVersion ().equals (openApiVersion );
723
728
724
- return (! RequestMethod . GET . equals ( requestMethod ) && (parameterInfo .getParameterModel () == null || parameterInfo .getParameterModel ().getIn () == null ) && !delegatingMethodParameter .isParameterObject ())
729
+ return (isBodyAllowed && (parameterInfo .getParameterModel () == null || parameterInfo .getParameterModel ().getIn () == null ) && !delegatingMethodParameter .isParameterObject ())
725
730
&&
726
731
((methodParameter .getParameterAnnotation (io .swagger .v3 .oas .annotations .parameters .RequestBody .class ) != null
727
732
|| methodParameter .getParameterAnnotation (org .springframework .web .bind .annotation .RequestBody .class ) != null
0 commit comments