71
71
import org .springdoc .core .models .ParameterId ;
72
72
import org .springdoc .core .models .ParameterInfo ;
73
73
import org .springdoc .core .models .RequestBodyInfo ;
74
+ import org .springdoc .core .properties .SpringDocConfigProperties .ApiDocs .OpenApiVersion ;
74
75
import org .springdoc .core .providers .JavadocProvider ;
75
76
import org .springdoc .core .utils .SpringDocAnnotationsUtils ;
76
77
@@ -296,7 +297,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
296
297
}
297
298
298
299
if (!isParamToIgnore (methodParameter )) {
299
- parameter = buildParams (parameterInfo , components , requestMethod , methodAttributes .getJsonViewAnnotation ());
300
+ parameter = buildParams (parameterInfo , components , requestMethod , methodAttributes .getJsonViewAnnotation (), openAPI . getOpenapi () );
300
301
// Merge with the operation parameters
301
302
parameter = GenericParameterService .mergeParameter (operationParameters , parameter );
302
303
List <Annotation > parameterAnnotations = Arrays .asList (methodParameter .getParameterAnnotations ());
@@ -310,7 +311,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
310
311
}
311
312
applyBeanValidatorAnnotations (parameter , parameterAnnotations );
312
313
}
313
- else if (!RequestMethod .GET .equals (requestMethod )) {
314
+ else if (!RequestMethod .GET .equals (requestMethod ) || OpenApiVersion . OPENAPI_3_1 . getVersion (). equals ( openAPI . getOpenapi ()) ) {
314
315
if (operation .getRequestBody () != null )
315
316
requestBodyInfo .setRequestBody (operation .getRequestBody ());
316
317
requestBodyService .calculateRequestBodyInfo (components , methodAttributes ,
@@ -499,10 +500,11 @@ public boolean isValidParameter(Parameter parameter) {
499
500
* @param components the components
500
501
* @param requestMethod the request method
501
502
* @param jsonView the json view
503
+ * @param openApiVersion the open api version
502
504
* @return the parameter
503
505
*/
504
506
public Parameter buildParams (ParameterInfo parameterInfo , Components components ,
505
- RequestMethod requestMethod , JsonView jsonView ) {
507
+ RequestMethod requestMethod , JsonView jsonView , String openApiVersion ) {
506
508
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
507
509
if (parameterInfo .getParamType () != null ) {
508
510
if (!ValueConstants .DEFAULT_NONE .equals (parameterInfo .getDefaultValue ()))
@@ -512,7 +514,7 @@ public Parameter buildParams(ParameterInfo parameterInfo, Components components,
512
514
return this .buildParam (parameterInfo , components , jsonView );
513
515
}
514
516
// By default
515
- if (!isRequestBodyParam (requestMethod , parameterInfo )) {
517
+ if (!isRequestBodyParam (requestMethod , parameterInfo , openApiVersion )) {
516
518
parameterInfo .setRequired (!((DelegatingMethodParameter ) methodParameter ).isNotRequired () && !methodParameter .isOptional ());
517
519
//parameterInfo.setParamType(QUERY_PARAM);
518
520
parameterInfo .setDefaultValue (null );
@@ -726,13 +728,15 @@ private void applyValidationsToSchema(Map<String, Annotation> annos, Schema<?> s
726
728
*
727
729
* @param requestMethod the request method
728
730
* @param parameterInfo the parameter info
731
+ * @param openApiVersion the open api version
729
732
* @return the boolean
730
733
*/
731
- private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo ) {
734
+ private boolean isRequestBodyParam (RequestMethod requestMethod , ParameterInfo parameterInfo , String openApiVersion ) {
732
735
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
733
736
DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter ) methodParameter ;
737
+ Boolean isBodyAllowed = !RequestMethod .GET .equals (requestMethod ) || OpenApiVersion .OPENAPI_3_1 .getVersion ().equals (openApiVersion );
734
738
735
- return (! RequestMethod . GET . equals ( requestMethod ) && (parameterInfo .getParameterModel () == null || parameterInfo .getParameterModel ().getIn () == null ) && !delegatingMethodParameter .isParameterObject ())
739
+ return (isBodyAllowed && (parameterInfo .getParameterModel () == null || parameterInfo .getParameterModel ().getIn () == null ) && !delegatingMethodParameter .isParameterObject ())
736
740
&&
737
741
((methodParameter .getParameterAnnotation (io .swagger .v3 .oas .annotations .parameters .RequestBody .class ) != null
738
742
|| methodParameter .getParameterAnnotation (org .springframework .web .bind .annotation .RequestBody .class ) != null
0 commit comments