Skip to content

Commit c207364

Browse files
committed
changes report #1814.
1 parent 936b649 commit c207364

File tree

7 files changed

+210
-9
lines changed

7 files changed

+210
-9
lines changed

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
* The type Abstract open api resource.
123123
* @author bnasslahsen
124124
* @author kevinraddatz
125+
* @author hyeonisism
126+
* @author doljae
125127
*/
126128
public abstract class AbstractOpenApiResource extends SpecFilter {
127129

@@ -316,7 +318,7 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
316318
Map<String, Object> mappingsMap = openAPIService.getMappingsMap().entrySet().stream()
317319
.filter(controller -> (AnnotationUtils.findAnnotation(controller.getValue().getClass(),
318320
Hidden.class) == null))
319-
.filter(controller -> !AbstractOpenApiResource.isHiddenRestControllers(controller.getValue().getClass()))
321+
.filter(controller -> !isHiddenRestControllers(controller.getValue().getClass()))
320322
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1));
321323

322324
Map<String, Object> findControllerAdvice = openAPIService.getControllerAdviceMap();

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/core/data/DataRestRequestService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ else if (methodParameter.getParameterAnnotation(BackendId.class) != null) {
175175
parameterInfo.setParameterModel(parameter);
176176
}
177177
if (!ArrayUtils.isEmpty(methodParameter.getParameterAnnotations()))
178-
parameter = requestBuilder.buildParams(parameterInfo, openAPI.getComponents(), requestMethod, null);
179-
178+
parameter = requestBuilder.buildParams(parameterInfo, openAPI.getComponents(), requestMethod, null,
179+
openAPI.getOpenapi());
180180
addParameters(openAPI, requestMethod, methodAttributes, operation, methodParameter, parameterInfo, parameter);
181181
}
182182
}

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/AbstractRequestService.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.springdoc.core.models.ParameterId;
7272
import org.springdoc.core.models.ParameterInfo;
7373
import org.springdoc.core.models.RequestBodyInfo;
74+
import org.springdoc.core.properties.SpringDocConfigProperties.ApiDocs.OpenApiVersion;
7475
import org.springdoc.core.providers.JavadocProvider;
7576
import org.springdoc.core.utils.SpringDocAnnotationsUtils;
7677

@@ -296,7 +297,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
296297
}
297298

298299
if (!isParamToIgnore(methodParameter)) {
299-
parameter = buildParams(parameterInfo, components, requestMethod, methodAttributes.getJsonViewAnnotation());
300+
parameter = buildParams(parameterInfo, components, requestMethod, methodAttributes.getJsonViewAnnotation(),openAPI.getOpenapi());
300301
// Merge with the operation parameters
301302
parameter = GenericParameterService.mergeParameter(operationParameters, parameter);
302303
List<Annotation> parameterAnnotations = Arrays.asList(methodParameter.getParameterAnnotations());
@@ -310,7 +311,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
310311
}
311312
applyBeanValidatorAnnotations(parameter, parameterAnnotations);
312313
}
313-
else if (!RequestMethod.GET.equals(requestMethod)) {
314+
else if (!RequestMethod.GET.equals(requestMethod) || OpenApiVersion.OPENAPI_3_1.getVersion().equals(openAPI.getOpenapi())) {
314315
if (operation.getRequestBody() != null)
315316
requestBodyInfo.setRequestBody(operation.getRequestBody());
316317
requestBodyService.calculateRequestBodyInfo(components, methodAttributes,
@@ -499,10 +500,11 @@ public boolean isValidParameter(Parameter parameter) {
499500
* @param components the components
500501
* @param requestMethod the request method
501502
* @param jsonView the json view
503+
* @param openApiVersion the open api version
502504
* @return the parameter
503505
*/
504506
public Parameter buildParams(ParameterInfo parameterInfo, Components components,
505-
RequestMethod requestMethod, JsonView jsonView) {
507+
RequestMethod requestMethod, JsonView jsonView, String openApiVersion) {
506508
MethodParameter methodParameter = parameterInfo.getMethodParameter();
507509
if (parameterInfo.getParamType() != null) {
508510
if (!ValueConstants.DEFAULT_NONE.equals(parameterInfo.getDefaultValue()))
@@ -512,7 +514,7 @@ public Parameter buildParams(ParameterInfo parameterInfo, Components components,
512514
return this.buildParam(parameterInfo, components, jsonView);
513515
}
514516
// By default
515-
if (!isRequestBodyParam(requestMethod, parameterInfo)) {
517+
if (!isRequestBodyParam(requestMethod, parameterInfo,openApiVersion)) {
516518
parameterInfo.setRequired(!((DelegatingMethodParameter) methodParameter).isNotRequired() && !methodParameter.isOptional());
517519
//parameterInfo.setParamType(QUERY_PARAM);
518520
parameterInfo.setDefaultValue(null);
@@ -726,13 +728,15 @@ private void applyValidationsToSchema(Map<String, Annotation> annos, Schema<?> s
726728
*
727729
* @param requestMethod the request method
728730
* @param parameterInfo the parameter info
731+
* @param openApiVersion the open api version
729732
* @return the boolean
730733
*/
731-
private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo parameterInfo) {
734+
private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo parameterInfo, String openApiVersion) {
732735
MethodParameter methodParameter = parameterInfo.getMethodParameter();
733736
DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter) methodParameter;
737+
Boolean isBodyAllowed = !RequestMethod.GET.equals(requestMethod) || OpenApiVersion.OPENAPI_3_1.getVersion().equals(openApiVersion);
734738

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())
736740
&&
737741
((methodParameter.getParameterAnnotation(io.swagger.v3.oas.annotations.parameters.RequestBody.class) != null
738742
|| methodParameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestBody.class) != null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2022 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.v31.app6;
24+
25+
import java.time.Instant;
26+
27+
public class DummyData {
28+
29+
String trackerId;
30+
31+
Instant timestamp;
32+
33+
Double value;
34+
35+
public String getTrackerId() {
36+
return trackerId;
37+
}
38+
39+
public void setTrackerId(String trackerId) {
40+
this.trackerId = trackerId;
41+
}
42+
43+
public Instant getTimestamp() {
44+
return timestamp;
45+
}
46+
47+
public void setTimestamp(Instant timestamp) {
48+
this.timestamp = timestamp;
49+
}
50+
51+
public Double getValue() {
52+
return value;
53+
}
54+
55+
public void setValue(Double value) {
56+
this.value = value;
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2022 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.v31.app6;
24+
25+
import org.springframework.web.bind.annotation.GetMapping;
26+
import org.springframework.web.bind.annotation.RequestBody;
27+
import org.springframework.web.bind.annotation.RestController;
28+
29+
@RestController
30+
public class GetBodyController {
31+
32+
@GetMapping(value = "/get/body")
33+
DummyData getBody(@RequestBody DummyData dummyData) {
34+
return dummyData;
35+
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2022 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.v31.app6;
24+
25+
import test.org.springdoc.api.v31.AbstractSpringDocV31Test;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
29+
public class SpringDocApp6Test extends AbstractSpringDocV31Test {
30+
31+
@SpringBootApplication
32+
static class SpringDocTestApp {
33+
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/get/body": {
15+
"get": {
16+
"tags": [
17+
"get-body-controller"
18+
],
19+
"operationId": "getBody",
20+
"requestBody": {
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"$ref": "#/components/schemas/DummyData"
25+
}
26+
}
27+
},
28+
"required": true
29+
},
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"$ref": "#/components/schemas/DummyData"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
},
45+
"components": {
46+
"schemas": {
47+
"DummyData": {
48+
"properties": {
49+
"trackerId": {
50+
"type": "string"
51+
},
52+
"timestamp": {
53+
"type": "string",
54+
"format": "date-time"
55+
},
56+
"value": {
57+
"type": "number",
58+
"format": "double"
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)