Skip to content

Tags with only name provided are being added to the openAPI.tags field #1648

Closed
@Mitchell-Kovacs

Description

@Mitchell-Kovacs

Describe the bug

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions