Consider a Spring Boot REST API project using Swagger/OpenAPI annotations. If you assign different @Tag annotations to controller classes, what is the effect on the generated API documentation?
import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @Tag(name = "User Management") @RestController public class UserController { @GetMapping("/users") public String getUsers() { return "List of users"; } } @Tag(name = "Product Management") @RestController public class ProductController { @GetMapping("/products") public String getProducts() { return "List of products"; } }
Think about how Swagger UI organizes endpoints visually when tags are used.
Using @Tag annotations on controllers groups the APIs in the generated Swagger UI under those tag names, making it easier to navigate related endpoints.
Which of the following code snippets correctly applies a tag to a single API method in Spring Boot using OpenAPI annotations?
Remember that @Tag is for classes, while @Operation can tag methods.
The @Operation annotation has a tags attribute to assign tags to individual API methods. The other options misuse @Tag or its syntax.
Given the following controller, the tag 'Inventory' does not show in Swagger UI. What is the most likely cause?
import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController @Tag(name = "Inventory") public class InventoryController { @GetMapping("/inventory") public String getInventory() { return "Inventory list"; } }
Check if the package containing the controller is included in the OpenAPI scan.
If the OpenAPI configuration does not scan the package where the controller is, the tags and endpoints won't appear in Swagger UI even if annotated correctly.
Consider this Spring Boot API method annotated with multiple tags. What will be the grouping behavior in Swagger UI?
import io.swagger.v3.oas.annotations.Operation; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class MultiTagController { @Operation(tags = {"Payments", "Transactions"}) @GetMapping("/payments") public String getPayments() { return "Payments data"; } }
Think about how Swagger UI handles multiple tags on one endpoint.
Swagger UI lists the endpoint under each tag specified, so it will show in both 'Payments' and 'Transactions' groups.
Which of the following is the best explanation for why developers use tags to group APIs in Spring Boot projects with Swagger/OpenAPI?
Consider the user experience of API consumers reading the documentation.
Tags are used to organize APIs into meaningful groups in the documentation, improving clarity and navigation. They do not affect security or controller functionality directly.