What is the purpose of grouping APIs by tags in Spring Boot?
Grouping APIs by tags helps organize endpoints into meaningful categories. This makes the API documentation easier to read and understand for developers and users.
Click to reveal answer
beginner
How do you define a tag for an API endpoint in Spring Boot using OpenAPI annotations?
You use the @Tag annotation at the class level or the @Operation annotation's tags attribute at the method level to assign tags to API endpoints.
Click to reveal answer
beginner
Which annotation is commonly used to group multiple API endpoints under one tag in Spring Boot?
The @Tag annotation is used on a controller class to group all its endpoints under a single tag in the API documentation.
Click to reveal answer
beginner
What benefit does grouping APIs by tags provide in Swagger UI?
It visually separates API endpoints into sections, making it easier to navigate and find related endpoints quickly.
Click to reveal answer
intermediate
Can you assign multiple tags to a single API endpoint in Spring Boot? How?
Yes, by specifying multiple tags in the @Operation annotation's tags attribute as an array of strings.
Click to reveal answer
Which annotation is used to group API endpoints by tags in Spring Boot?
A@Tag
B@Group
C@Category
D@Section
✗ Incorrect
The @Tag annotation is the standard way to group API endpoints by tags in Spring Boot's OpenAPI support.
Where do you place the @Tag annotation to group all endpoints of a controller?
AIn application.properties
BOn each method
COn the controller class
DIn a separate config file
✗ Incorrect
Placing @Tag on the controller class groups all its endpoints under that tag.
How can you assign multiple tags to a single API method?
AUse multiple @Tag annotations
BUse @Operation(tags = {"tag1", "tag2"})
CUse @Tags annotation
DAssign tags in application.yml
✗ Incorrect
The @Operation annotation allows specifying multiple tags as an array.
What is a key benefit of grouping APIs by tags in Swagger UI?
AImproves navigation and readability
BIncreases API speed
CSecures the API
DAutomatically generates tests
✗ Incorrect
Grouping APIs by tags organizes the documentation, making it easier to navigate.
Which of these is NOT a correct way to group APIs by tags?
ADefining tags in OpenAPI configuration
BUsing @Operation tags attribute on methods
CUsing @Tag on controller classes
DUsing @Group annotation
✗ Incorrect
There is no @Group annotation in Spring Boot for grouping APIs by tags.
Explain how to group API endpoints by tags in Spring Boot and why it is useful.
Think about how tags help organize and label API endpoints.
You got /4 concepts.
Describe how multiple tags can be assigned to a single API endpoint in Spring Boot.
Look at the @Operation annotation's tags attribute.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of using @Tag annotation in Spring Boot controllers?
easy
A. To specify the database table for the API
B. To group related APIs for better documentation organization
C. To define the HTTP method of an API endpoint
D. To secure APIs with authentication
Solution
Step 1: Understand the role of @Tag
The @Tag annotation is used to group APIs logically in documentation tools like Swagger.
Step 2: Identify its effect on API docs
Grouping APIs by tags makes the documentation easier to read and navigate for users.
Final Answer:
To group related APIs for better documentation organization -> Option B
Quick Check:
@Tag groups APIs = D [OK]
Hint: Remember @Tag groups APIs for docs, not for security or DB [OK]
Common Mistakes:
Confusing @Tag with security annotations
Thinking @Tag sets HTTP methods
Assuming @Tag relates to database mapping
2. Which of the following is the correct way to add a tag named "User Management" to a Spring Boot controller?
easy
A. @Tag(name = "User Management") above the controller class
B. @Tag(value = "User Management") above each method
C. @Tag("User Management") inside the method body
D. @Tag(name = "User Management") inside the application.properties file
Solution
Step 1: Identify correct @Tag usage
The @Tag annotation is placed above the controller class with the name attribute to specify the tag.
Step 2: Confirm placement and syntax
It should not be inside methods or properties files; it applies at the class level for grouping all endpoints.
Final Answer:
@Tag(name = "User Management") above the controller class -> Option A
Quick Check:
@Tag(name=...) on class = A [OK]
Hint: Place @Tag(name=...) above controller class, not methods or config [OK]
Common Mistakes:
Using @Tag inside method bodies
Using 'value' instead of 'name' attribute
Placing @Tag in properties files
3. Given this controller code snippet:
@RestController
@Tag(name = "Orders")
public class OrderController {
@GetMapping("/orders")
public List<String> getOrders() { return List.of("order1", "order2"); }
}
What tag will appear in the generated API documentation for the /orders endpoint?
medium
A. "Orders"
B. No tag will appear
C. "OrderController"
D. "getOrders"
Solution
Step 1: Check @Tag annotation on controller
The controller class has @Tag(name = "Orders"), so all its endpoints inherit this tag.
Step 2: Determine tag shown in docs
The /orders endpoint will be grouped under the "Orders" tag in the API documentation.
Final Answer:
"Orders" -> Option A
Quick Check:
Controller @Tag name = "Orders" means tag = B [OK]
Hint: Controller-level @Tag sets tag for all its endpoints [OK]
Common Mistakes:
Expecting method name as tag
Thinking no tag appears without method-level @Tag
Confusing class name with tag
4. Consider this controller code:
@RestController
@Tag(name = "Products")
public class ProductController {
@GetMapping("/products")
public List<String> getProducts() { return List.of("prod1", "prod2"); }
@Tag(name = "Special")
@GetMapping("/products/special")
public List<String> getSpecialProducts() { return List.of("special1"); }
}
What is the problem with this code regarding API grouping by tags?
medium
A. Multiple @Tag annotations cause runtime errors
B. Method-level @Tag overrides class-level @Tag correctly
C. @Tag cannot be used on methods, causing a compile error
D. Method-level @Tag is ignored; only class-level @Tag works
Solution
Step 1: Check @Tag usage rules
In Spring Boot with OpenAPI, @Tag is primarily for class-level use to group endpoints. Method-level @Tag is ignored for grouping purposes.
Step 2: Identify its effect on API docs
The /products/special endpoint will still be grouped under the "Products" tag, as method-level @Tag does not override class-level grouping.
Final Answer:
Method-level @Tag is ignored; only class-level @Tag works -> Option D
Quick Check:
Method-level @Tag ignored = A [OK]
Hint: Use @Tag only on controller classes, not on methods [OK]
Common Mistakes:
Assuming method-level @Tag overrides class-level
Thinking multiple @Tag annotations cause runtime errors
Ignoring that method-level @Tag is invalid
5. You have two controllers:
@RestController
@Tag(name = "Users")
public class UserController {
@GetMapping("/users")
public List<String> getUsers() { return List.of("user1", "user2"); }
}
@RestController
@Tag(name = "Admins")
public class AdminController {
@GetMapping("/admins")
public List<String> getAdmins() { return List.of("admin1"); }
}
How will the API documentation group these endpoints?
hard
A. No tags will appear in the documentation
B. All endpoints under a single "Users" tag
C. Endpoints grouped separately under "Users" and "Admins" tags
D. Endpoints grouped under controller class names as tags
Solution
Step 1: Identify tags on each controller
UserController has @Tag(name = "Users") and AdminController has @Tag(name = "Admins").
Step 2: Understand grouping in docs
Each controller's endpoints are grouped under their respective tags in the API docs.
Final Answer:
Endpoints grouped separately under "Users" and "Admins" tags -> Option C
Quick Check:
Separate @Tag names create separate groups = A [OK]
Hint: Different @Tag names on controllers create separate groups [OK]
Common Mistakes:
Assuming all endpoints merge under one tag
Expecting no tags without method-level @Tag
Thinking controller class names become tags automatically
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.