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 ,
@@ -494,10 +496,11 @@ public boolean isValidParameter(Parameter parameter) {
494
496
* @param components the components
495
497
* @param requestMethod the request method
496
498
* @param jsonView the json view
499
+ * @param openApiVersion the open api version
497
500
* @return the parameter
498
501
*/
499
502
public Parameter buildParams (ParameterInfo parameterInfo , Components components ,
500
- RequestMethod requestMethod , JsonView jsonView ) {
503
+ RequestMethod requestMethod , JsonView jsonView , String openApiVersion ) {
501
504
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
502
505
if (parameterInfo .getParamType () != null ) {
503
506
if (!ValueConstants .DEFAULT_NONE .equals (parameterInfo .getDefaultValue ()))
@@ -507,7 +510,7 @@ public Parameter buildParams(ParameterInfo parameterInfo, Components components,
507
510
return this .buildParam (parameterInfo , components , jsonView );
508
511
}
509
512
// By default
510
- if (!isRequestBodyParam (requestMethod , parameterInfo )) {
513
+ if (!isRequestBodyParam (requestMethod , parameterInfo , openApiVersion )) {
511
514
parameterInfo .setRequired (!((DelegatingMethodParameter ) methodParameter ).isNotRequired () && !methodParameter .isOptional ());
512
515
//parameterInfo.setParamType(QUERY_PARAM);
513
516
parameterInfo .setDefaultValue (null );
@@ -721,13 +724,15 @@ private void applyValidationsToSchema(Map<String, Annotation> annos, Schema<?> s
721
724
*
722
725
* @param requestMethod the request method
723
726
* @param parameterInfo the parameter info
727
+ * @param openApiVersion the open api version
724
728
* @return the boolean
725
729
*/
726
- private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo ) {
730
+ private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo , String openApiVersion ) {
727
731
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
728
732
DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter ) methodParameter ;
733
+ Boolean isBodyAllowed = !RequestMethod .GET .equals (requestMethod ) || OpenApiVersion .OPENAPI_3_1 .getVersion ().equals (openApiVersion );
729
734
730
- return (! RequestMethod . GET . equals ( requestMethod ) && (parameterInfo .getParameterModel () == null || parameterInfo .getParameterModel ().getIn () == null ) && !delegatingMethodParameter .isParameterObject ())
735
+ return (isBodyAllowed && (parameterInfo .getParameterModel () == null || parameterInfo .getParameterModel ().getIn () == null ) && !delegatingMethodParameter .isParameterObject ())
731
736
&&
732
737
((methodParameter .getParameterAnnotation (io .swagger .v3 .oas .annotations .parameters .RequestBody .class ) != null
733
738
|| methodParameter .getParameterAnnotation (org .springframework .web .bind .annotation .RequestBody .class ) != null
0 commit comments