Skip to content

Commit 85caf76

Browse files
committed
Changes report: Tags with only name provided are being added to the openAPI.tags field #1648.
1 parent c18ac9b commit 85caf76

File tree

29 files changed

+162
-175
lines changed

29 files changed

+162
-175
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/OpenAPIService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ public Operation buildTags(HandlerMethod handlerMethod, Operation operation, Ope
341341
Set<io.swagger.v3.oas.models.tags.Tag> tags = new HashSet<>();
342342
Set<String> tagsStr = new HashSet<>();
343343

344-
buildTagsFromClass(handlerMethod.getBeanType(), tags, tagsStr, locale);
345344
buildTagsFromMethod(handlerMethod.getMethod(), tags, tagsStr, locale);
345+
buildTagsFromClass(handlerMethod.getBeanType(), tags, tagsStr, locale);
346346

347347
if (!CollectionUtils.isEmpty(tagsStr))
348348
tagsStr = tagsStr.stream()
@@ -436,13 +436,14 @@ private void buildTagsFromMethod(Method method, Set<io.swagger.v3.oas.models.tag
436436
*/
437437
private void addTags(List<Tag> sourceTags, Set<io.swagger.v3.oas.models.tags.Tag> tags, Locale locale) {
438438
Optional<Set<io.swagger.v3.oas.models.tags.Tag>> optionalTagSet = AnnotationsUtils
439-
.getTags(sourceTags.toArray(new Tag[0]), false);
439+
.getTags(sourceTags.toArray(new Tag[0]), true);
440440
optionalTagSet.ifPresent(tagsSet -> {
441441
tagsSet.forEach(tag -> {
442442
tag.name(propertyResolverUtils.resolve(tag.getName(), locale));
443443
tag.description(propertyResolverUtils.resolve(tag.getDescription(), locale));
444+
if (tags.stream().noneMatch(t -> t.getName().equals(tag.getName())))
445+
tags.add(tag);
444446
});
445-
tags.addAll(tagsSet);
446447
});
447448
}
448449

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2022 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
package test.org.springdoc.api.v30.app187;
26+
27+
import io.swagger.v3.oas.annotations.ExternalDocumentation;
28+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
29+
import io.swagger.v3.oas.annotations.Operation;
30+
import io.swagger.v3.oas.annotations.tags.Tag;
31+
32+
import org.springframework.web.bind.annotation.GetMapping;
33+
import org.springframework.web.bind.annotation.RestController;
34+
35+
@RestController
36+
@OpenAPIDefinition(tags = {
37+
@Tag(name = "Definition First Tag"),
38+
@Tag(name = "Definition Second Tag full", description = "desc definition")
39+
})
40+
@Tag(name = "Second Tag")
41+
@Tag(name = "Fourth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class"))
42+
@Tag(name = "Fifth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class"))
43+
@Tag(name = "Sixth Tag")
44+
public class HelloController {
45+
46+
@GetMapping("/hello")
47+
@Operation(tags = {"Example Tag", "Second Tag"})
48+
@Tag(name = "Third Tag")
49+
@Tag(name = "Second Tag")
50+
@Tag(name = "Fourth Tag Full", description = "desc", externalDocs = @ExternalDocumentation(description = "docs desc"))
51+
public void hello() {}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2022 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
package test.org.springdoc.api.v30.app187;
26+
27+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
28+
29+
import org.springframework.boot.autoconfigure.SpringBootApplication;
30+
31+
public class SpringDocApp187Test extends AbstractSpringDocV30Test {
32+
33+
@SpringBootApplication
34+
static class SpringDocTestApp {}
35+
36+
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app1.json

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,6 @@
1414
"description": "Generated server url"
1515
}
1616
],
17-
"tags": [
18-
{
19-
"name": "inventory"
20-
},
21-
{
22-
"name": "people"
23-
},
24-
{
25-
"name": "tea"
26-
},
27-
{
28-
"name": "items"
29-
}
30-
],
3117
"paths": {
3218
"/{email}": {
3319
"get": {
@@ -436,12 +422,12 @@
436422
}
437423
}
438424
},
439-
"400": {
440-
"description": "invalid input, object invalid"
441-
},
442425
"201": {
443426
"description": "item created"
444427
},
428+
"400": {
429+
"description": "invalid input, object invalid"
430+
},
445431
"409": {
446432
"description": "an existing item already exists"
447433
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app100.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "hello-ap1"
16-
},
17-
{
18-
"name": "hello-ap2"
19-
}
20-
],
2113
"paths": {
2214
"/search": {
2315
"get": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app104.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "design"
16-
}
17-
],
1813
"paths": {
1914
"/design": {
2015
"get": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app122.json

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "example"
16-
}
17-
],
1813
"paths": {
1914
"/": {
2015
"post": {
@@ -50,21 +45,21 @@
5045
},
5146
"components": {
5247
"schemas": {
53-
"CustomerDto": {
48+
"WrapperCustomerDto": {
5449
"type": "object",
5550
"properties": {
56-
"baseStr": {
57-
"type": "string"
58-
},
59-
"customerName": {
51+
"wrapper": {
6052
"type": "string"
6153
}
6254
}
6355
},
64-
"WrapperCustomerDto": {
56+
"CustomerDto": {
6557
"type": "object",
6658
"properties": {
67-
"wrapper": {
59+
"baseStr": {
60+
"type": "string"
61+
},
62+
"customerName": {
6863
"type": "string"
6964
}
7065
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app134-1.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "The sample resource"
16-
}
17-
],
1813
"paths": {
1914
"/{id}": {
2015
"get": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app134-2.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "The sample resource"
16-
}
17-
],
1813
"paths": {
1914
"/search": {
2015
"post": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app134-3.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "The sample resource"
16-
}
17-
],
1813
"paths": {
1914
"/{id}": {
2015
"get": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app134-4.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "The sample resource"
16-
}
17-
],
1813
"paths": {
1914
"/{id}": {
2015
"get": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app134-5.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "The sample resource"
16-
}
17-
],
1813
"paths": {
1914
"/search": {
2015
"post": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app14.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
{
1515
"name": "Hello! Welcome to our website!",
1616
"description": "This is a test message"
17-
},
18-
{
19-
"name": "Change the language"
2017
}
2118
],
2219
"paths": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app180.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "REST Service"
16-
}
17-
],
1813
"paths": {
1914
"/api/testWithoutSchema": {
2015
"post": {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"openapi": "3.0.1",
3+
"servers": [
4+
{
5+
"url": "http://localhost",
6+
"description": "Generated server url"
7+
}
8+
],
9+
"tags": [
10+
{
11+
"name": "Definition Second Tag full",
12+
"description": "desc definition"
13+
},
14+
{
15+
"name": "Fifth Tag Full",
16+
"description": "desc class",
17+
"externalDocs": {
18+
"description": "docs desc class"
19+
}
20+
},
21+
{
22+
"name": "Definition First Tag"
23+
},
24+
{
25+
"name": "Fourth Tag Full",
26+
"description": "desc",
27+
"externalDocs": {
28+
"description": "docs desc"
29+
}
30+
}
31+
],
32+
"paths": {
33+
"/hello": {
34+
"get": {
35+
"tags": [
36+
"Sixth Tag",
37+
"Second Tag",
38+
"Example Tag",
39+
"Third Tag",
40+
"Fifth Tag Full",
41+
"Fourth Tag Full"
42+
],
43+
"operationId": "hello",
44+
"responses": {
45+
"200": {
46+
"description": "OK"
47+
}
48+
}
49+
}
50+
}
51+
},
52+
"components": {}
53+
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app55.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "health"
16-
}
17-
],
1813
"paths": {
1914
"/ping": {
2015
"get": {

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app62.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"description": "Generated server url"
1111
}
1212
],
13-
"tags": [
14-
{
15-
"name": "Test Controller"
16-
}
17-
],
1813
"paths": {
1914
"/test": {
2015
"get": {

0 commit comments

Comments
 (0)