Skip to content

Commit b7c3341

Browse files
author
bnasslahsen
committed
PR merge
1 parent 01c5392 commit b7c3341

File tree

4 files changed

+209
-1
lines changed

4 files changed

+209
-1
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractRequestBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ private Parameter buildParams(ParameterInfo parameterInfo, Components components
263263

264264
}
265265
else if (requestParam != null) {
266-
requestInfo = new RequestInfo(ParameterType.QUERY_PARAM, requestParam.value(), requestParam.required(),
266+
boolean isOptional = Optional.class.equals(parameters.getType());
267+
requestInfo = new RequestInfo(ParameterType.QUERY_PARAM, requestParam.value(), requestParam.required() && !isOptional,
267268
requestParam.defaultValue());
268269
parameter = buildParam(parameterInfo, components, requestInfo, jsonView);
269270
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app78;
20+
21+
<<<<<<< HEAD
22+
import java.util.concurrent.CompletableFuture;
23+
import java.util.concurrent.CompletionStage;
24+
25+
import org.springframework.http.ResponseEntity;
26+
import org.springframework.web.bind.annotation.RequestMapping;
27+
import org.springframework.web.bind.annotation.RequestMethod;
28+
import org.springframework.web.bind.annotation.RestController;
29+
30+
@RestController
31+
public class HelloController {
32+
33+
@RequestMapping(value = "/person1", method = RequestMethod.GET)
34+
private CompletionStage<ResponseEntity<PersonDTO>> getPerson1(String str) {
35+
return null;
36+
}
37+
38+
@RequestMapping(value = "/person2", method = RequestMethod.GET)
39+
private CompletableFuture<PersonDTO> getPerson2(String str) {
40+
return null;
41+
}
42+
43+
}
44+
=======
45+
import org.springframework.http.MediaType;
46+
import org.springframework.web.bind.annotation.GetMapping;
47+
import org.springframework.web.bind.annotation.RequestParam;
48+
import org.springframework.web.bind.annotation.RestController;
49+
50+
import java.util.Optional;
51+
52+
@RestController
53+
public class HelloController {
54+
55+
@GetMapping(produces = MediaType.TEXT_PLAIN_VALUE, path = "/test")
56+
public String echo(@RequestParam Optional<String> text) {
57+
return text.orElse("not-specified");
58+
}
59+
60+
}
61+
>>>>>>> 945f0e9e8cbfe98accf6bb98cc7274552fa47441
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app79;
20+
21+
import test.org.springdoc.api.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
26+
public class SpringDocApp78Test extends AbstractSpringDocTest {
27+
28+
@SpringBootApplication
29+
static class SpringDocTestApp {}
30+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"openapi": "3.0.1",
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+
<<<<<<< HEAD
15+
"/person1": {
16+
=======
17+
"/test": {
18+
>>>>>>> 945f0e9e8cbfe98accf6bb98cc7274552fa47441
19+
"get": {
20+
"tags": [
21+
"hello-controller"
22+
],
23+
<<<<<<< HEAD
24+
"operationId": "getPerson1",
25+
"parameters": [
26+
{
27+
"name": "str",
28+
"in": "query",
29+
"required": true,
30+
=======
31+
"operationId": "echo",
32+
"parameters": [
33+
{
34+
"name": "text",
35+
"in": "query",
36+
"required": false,
37+
>>>>>>> 945f0e9e8cbfe98accf6bb98cc7274552fa47441
38+
"schema": {
39+
"type": "string"
40+
}
41+
}
42+
],
43+
"responses": {
44+
"200": {
45+
"description": "default response",
46+
"content": {
47+
<<<<<<< HEAD
48+
"*/*": {
49+
"schema": {
50+
"$ref": "#/components/schemas/PersonDTO"
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
},
58+
"/person2": {
59+
"get": {
60+
"tags": [
61+
"hello-controller"
62+
],
63+
"operationId": "getPerson2",
64+
"parameters": [
65+
{
66+
"name": "str",
67+
"in": "query",
68+
"required": true,
69+
"schema": {
70+
"type": "string"
71+
}
72+
}
73+
],
74+
"responses": {
75+
"200": {
76+
"description": "default response",
77+
"content": {
78+
"*/*": {
79+
"schema": {
80+
"$ref": "#/components/schemas/PersonDTO"
81+
=======
82+
"text/plain": {
83+
"schema": {
84+
"type": "string"
85+
>>>>>>> 945f0e9e8cbfe98accf6bb98cc7274552fa47441
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
},
94+
<<<<<<< HEAD
95+
"components": {
96+
"schemas": {
97+
"PersonDTO": {
98+
"type": "object",
99+
"properties": {
100+
"email": {
101+
"type": "string"
102+
},
103+
"firstName": {
104+
"type": "string"
105+
},
106+
"lastName": {
107+
"type": "string"
108+
}
109+
}
110+
}
111+
}
112+
}
113+
=======
114+
"components": {}
115+
>>>>>>> 945f0e9e8cbfe98accf6bb98cc7274552fa47441
116+
}

0 commit comments

Comments
 (0)