Skip to content

Commit 740827a

Browse files
committed
Tags with only name provided are being added to the openAPI.tags field. Fixes #1648.
1 parent 6b7a8e1 commit 740827a

File tree

29 files changed

+158
-175
lines changed

29 files changed

+158
-175
lines changed

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

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

333-
buildTagsFromClass(handlerMethod.getBeanType(), tags, tagsStr, locale);
334333
buildTagsFromMethod(handlerMethod.getMethod(), tags, tagsStr, locale);
334+
buildTagsFromClass(handlerMethod.getBeanType(), tags, tagsStr, locale);
335335

336336
if (!CollectionUtils.isEmpty(tagsStr))
337337
tagsStr = tagsStr.stream()
@@ -425,13 +425,14 @@ private void buildTagsFromMethod(Method method, Set<io.swagger.v3.oas.models.tag
425425
*/
426426
private void addTags(List<Tag> sourceTags, Set<io.swagger.v3.oas.models.tags.Tag> tags, Locale locale) {
427427
Optional<Set<io.swagger.v3.oas.models.tags.Tag>> optionalTagSet = AnnotationsUtils
428-
.getTags(sourceTags.toArray(new Tag[0]), false);
428+
.getTags(sourceTags.toArray(new Tag[0]), true);
429429
optionalTagSet.ifPresent(tagsSet -> {
430430
tagsSet.forEach(tag -> {
431431
tag.name(propertyResolverUtils.resolve(tag.getName(), locale));
432432
tag.description(propertyResolverUtils.resolve(tag.getDescription(), locale));
433+
if (tags.stream().noneMatch(t -> t.getName().equals(tag.getName())))
434+
tags.add(tag);
433435
});
434-
tags.addAll(tagsSet);
435436
});
436437
}
437438

springdoc-openapi-javadoc/src/test/resources/results/app1.json

Lines changed: 4 additions & 18 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": {
@@ -445,12 +431,12 @@
445431
}
446432
}
447433
},
448-
"400": {
449-
"description": "invalid input, object invalid"
450-
},
451434
"201": {
452435
"description": "item created"
453436
},
437+
"400": {
438+
"description": "invalid input, object invalid"
439+
},
454440
"409": {
455441
"description": "an existing item already exists"
456442
}
@@ -687,4 +673,4 @@
687673
}
688674
}
689675
}
690-
}
676+
}

springdoc-openapi-javadoc/src/test/resources/results/app100.json

Lines changed: 1 addition & 9 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": {
@@ -81,4 +73,4 @@
8173
}
8274
}
8375
}
84-
}
76+
}

springdoc-openapi-javadoc/src/test/resources/results/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-javadoc/src/test/resources/results/app122.json

Lines changed: 1 addition & 6 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": {
@@ -78,4 +73,4 @@
7873
}
7974
}
8075
}
81-
}
76+
}

springdoc-openapi-javadoc/src/test/resources/results/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-javadoc/src/test/resources/results/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-javadoc/src/test/resources/results/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-javadoc/src/test/resources/results/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-javadoc/src/test/resources/results/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-javadoc/src/test/resources/results/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-javadoc/src/test/resources/results/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": {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.v30.app187;
24+
25+
import io.swagger.v3.oas.annotations.ExternalDocumentation;
26+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
27+
import io.swagger.v3.oas.annotations.Operation;
28+
import io.swagger.v3.oas.annotations.tags.Tag;
29+
30+
import org.springframework.web.bind.annotation.GetMapping;
31+
import org.springframework.web.bind.annotation.RestController;
32+
33+
@RestController
34+
@OpenAPIDefinition(tags = {
35+
@Tag(name = "Definition First Tag"),
36+
@Tag(name = "Definition Second Tag full", description = "desc definition")
37+
})
38+
@Tag(name = "Second Tag")
39+
@Tag(name = "Fourth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class"))
40+
@Tag(name = "Fifth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class"))
41+
@Tag(name = "Sixth Tag")
42+
public class HelloController {
43+
44+
@GetMapping("/hello")
45+
@Operation(tags = {"Example Tag", "Second Tag"})
46+
@Tag(name = "Third Tag")
47+
@Tag(name = "Second Tag")
48+
@Tag(name = "Fourth Tag Full", description = "desc", externalDocs = @ExternalDocumentation(description = "docs desc"))
49+
public void hello() {}
50+
51+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.v30.app187;
24+
25+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
29+
public class SpringDocApp187Test extends AbstractSpringDocV30Test {
30+
31+
@SpringBootApplication
32+
static class SpringDocTestApp {}
33+
34+
}

springdoc-openapi-webmvc-core/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-webmvc-core/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-webmvc-core/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": {

0 commit comments

Comments
 (0)