Skip to content

Commit 2b06993

Browse files
author
bnasslahsen
committed
Improve the support of Pageable. Fixes #496
1 parent 7f82a76 commit 2b06993

File tree

7 files changed

+222
-11
lines changed

7 files changed

+222
-11
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.swagger.v3.oas.annotations.Hidden;
3737
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
3838
import io.swagger.v3.oas.annotations.tags.Tag;
39+
import io.swagger.v3.oas.annotations.tags.Tags;
3940
import io.swagger.v3.oas.models.Components;
4041
import io.swagger.v3.oas.models.OpenAPI;
4142
import io.swagger.v3.oas.models.Operation;
@@ -116,7 +117,7 @@ public class OpenAPIBuilder {
116117
this.openApiBuilderCustomisers = openApiBuilderCustomisers;
117118
}
118119

119-
private static String splitCamelCase(String str) {
120+
public static String splitCamelCase(String str) {
120121
return str.replaceAll(
121122
String.format(
122123
"%s|%s|%s",
@@ -180,13 +181,21 @@ public boolean isServersPresent() {
180181
}
181182

182183
public Operation buildTags(HandlerMethod handlerMethod, Operation operation, OpenAPI openAPI) {
184+
183185
// class tags
184-
Set<Tag> classTags =
185-
AnnotatedElementUtils.findAllMergedAnnotations(handlerMethod.getBeanType(), Tag.class);
186+
Set<Tags> tagsSet = AnnotatedElementUtils
187+
.findAllMergedAnnotations(handlerMethod.getBeanType(), Tags.class);
188+
Set<Tag> classTags = tagsSet.stream()
189+
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toSet());
190+
classTags.addAll(AnnotatedElementUtils.findAllMergedAnnotations(handlerMethod.getBeanType(), Tag.class));
186191

187192
// method tags
188-
Set<Tag> methodTags =
189-
AnnotatedElementUtils.findAllMergedAnnotations(handlerMethod.getMethod(), Tag.class);
193+
tagsSet = AnnotatedElementUtils
194+
.findAllMergedAnnotations(handlerMethod.getMethod(), Tags.class);
195+
Set<Tag> methodTags = tagsSet.stream()
196+
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toSet());
197+
methodTags.addAll(AnnotatedElementUtils.findAllMergedAnnotations(handlerMethod.getMethod(), Tag.class));
198+
190199

191200
List<Tag> allTags = new ArrayList<>();
192201
Set<String> tagsStr = new HashSet<>();
@@ -213,12 +222,12 @@ public Operation buildTags(HandlerMethod handlerMethod, Operation operation, Ope
213222
.getTags(allTags.toArray(new Tag[0]), true);
214223

215224
if (tags.isPresent()) {
216-
Set<io.swagger.v3.oas.models.tags.Tag> tagsSet = tags.get();
225+
Set<io.swagger.v3.oas.models.tags.Tag> tagSet = tags.get();
217226
// Existing tags
218227
List<io.swagger.v3.oas.models.tags.Tag> openApiTags = openAPI.getTags();
219228
if (!CollectionUtils.isEmpty(openApiTags))
220-
tagsSet.addAll(openApiTags);
221-
openAPI.setTags(new ArrayList<>(tagsSet));
229+
tagSet.addAll(openApiTags);
230+
openAPI.setTags(new ArrayList<>(tagSet));
222231
}
223232

224233
// Handle SecurityRequirement at operation level
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.app100;
20+
21+
import javax.validation.constraints.NotNull;
22+
23+
import io.swagger.v3.oas.annotations.tags.Tag;
24+
import io.swagger.v3.oas.annotations.tags.Tags;
25+
26+
import org.springframework.web.bind.annotation.GetMapping;
27+
import org.springframework.web.bind.annotation.RestController;
28+
29+
@RestController
30+
@Tags(value = @Tag(name="hello-ap1"))
31+
public class HelloController {
32+
33+
@GetMapping(value = "/search", produces = { "application/xml", "application/json" })
34+
@Tags(value = @Tag(name="hello-ap2"))
35+
public PersonDTO getAllPets(@NotNull String toto) {
36+
return null;
37+
}
38+
39+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.app100;
20+
21+
import io.swagger.v3.oas.annotations.media.Schema;
22+
23+
@Schema
24+
public class PersonDTO {
25+
private String email;
26+
27+
private String firstName;
28+
29+
private String lastName;
30+
31+
public PersonDTO() {
32+
}
33+
34+
public PersonDTO(final String email, final String firstName, final String lastName) {
35+
this.email = email;
36+
this.firstName = firstName;
37+
this.lastName = lastName;
38+
}
39+
40+
public String getEmail() {
41+
return email;
42+
}
43+
44+
public void setEmail(final String email) {
45+
this.email = email;
46+
}
47+
48+
public String getFirstName() {
49+
return firstName;
50+
}
51+
52+
public void setFirstName(final String firstName) {
53+
this.firstName = firstName;
54+
}
55+
56+
public String getLastName() {
57+
return lastName;
58+
}
59+
60+
public void setLastName(final String lastName) {
61+
this.lastName = lastName;
62+
}
63+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.app100;
20+
21+
22+
import test.org.springdoc.api.AbstractSpringDocTest;
23+
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
26+
public class SpringDocApp100Test extends AbstractSpringDocTest {
27+
28+
@SpringBootApplication
29+
static class SpringDocTestApp {}
30+
31+
}

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app99/HelloController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package test.org.springdoc.api.app99;
22

3-
import io.swagger.v3.oas.annotations.Operation;
4-
import io.swagger.v3.oas.annotations.Parameter;
53
import io.swagger.v3.oas.annotations.responses.ApiResponse;
64
import io.swagger.v3.oas.annotations.responses.ApiResponses;
5+
76
import org.springframework.web.bind.annotation.GetMapping;
87
import org.springframework.web.bind.annotation.RequestMapping;
98
import org.springframework.web.bind.annotation.RestController;

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app99/SpringDocApp99Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
package test.org.springdoc.api.app99;
2020

2121

22+
import test.org.springdoc.api.AbstractSpringDocTest;
23+
2224
import org.springframework.boot.autoconfigure.SpringBootApplication;
2325
import org.springframework.test.context.ActiveProfiles;
24-
import test.org.springdoc.api.AbstractSpringDocTest;
2526

2627
@ActiveProfiles("99")
2728
public class SpringDocApp99Test extends AbstractSpringDocTest {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
"/search": {
15+
"get": {
16+
"tags": [
17+
"hello-ap1",
18+
"hello-ap2"
19+
],
20+
"operationId": "getAllPets",
21+
"parameters": [
22+
{
23+
"name": "toto",
24+
"in": "query",
25+
"required": true,
26+
"schema": {
27+
"type": "string"
28+
}
29+
}
30+
],
31+
"responses": {
32+
"200": {
33+
"description": "default response",
34+
"content": {
35+
"application/xml": {
36+
"schema": {
37+
"$ref": "#/components/schemas/PersonDTO"
38+
}
39+
},
40+
"application/json": {
41+
"schema": {
42+
"$ref": "#/components/schemas/PersonDTO"
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
},
51+
"components": {
52+
"schemas": {
53+
"PersonDTO": {
54+
"type": "object",
55+
"properties": {
56+
"email": {
57+
"type": "string"
58+
},
59+
"firstName": {
60+
"type": "string"
61+
},
62+
"lastName": {
63+
"type": "string"
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)