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": {

0 commit comments

Comments
 (0)