Closed
Description
Describe the bug
- For the
@Tag
annotation, according to https://docs.swagger.io/swagger-core/v2.2.0/apidocs/io/swagger/v3/oas/annotations/tags/Tag.html,
When applied at method or class level, if only a name is provided, the tag will be added to operation only; if additional fields are also defined, like description or externalDocs, the Tag will also be added to openAPI.tags field
- Tags with only name defined will be added to the openAPI.tags field when they should only be added to the operation
- Occasionally, the tag with without any metadata will be selected in swagger-ui and information such as the description will not be shown
To Reproduce
- tested on spring-boot 2.6.7 and 2.5.13
- sprindoc-openapi-ui version 1.6.8
- Add the
io.swagger.v3.oas.annotations.tags.Tag
annotation on a class or method with only the name field populated - Example controller:
@RestController
@Tag(name = "Hello", description = "Hello World!")
@Tag(name = "Hello")
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "hello world";
}
}
- actual OpenAPI Description
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"tags": [
{
"name": "Hello",
"description": "Hello World!"
},
{
"name": "Hello"
}
],
"paths": {
"/hello": {
"get": {
"tags": [
"Hello"
],
"operationId": "hello",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {}
}
Expected behavior
- the Tag without description should not appear in the openAPI.tags field
- expected OpenAPI Description
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"tags": [
{
"name": "Hello",
"description": "Hello World!"
}
],
"paths": {
"/hello": {
"get": {
"tags": [
"Hello"
],
"operationId": "hello",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {}
}
- see https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#tag for more examples
- this looks to be related to Duplicate Tags #1625