0
0
Spring Bootframework~20 mins

Grouping APIs by tags in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
API Tagging Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does tagging affect API grouping in Spring Boot?

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?

Spring Boot
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";
    }
}
AThe APIs are grouped under separate sections named 'User Management' and 'Product Management' in the Swagger UI.
BThe APIs are merged into a single group ignoring the tags, so all endpoints appear together.
CThe tags cause a runtime error when starting the Spring Boot application.
DThe tags only affect the Java package structure but not the API documentation.
Attempts:
2 left
💡 Hint

Think about how Swagger UI organizes endpoints visually when tags are used.

📝 Syntax
intermediate
2:00remaining
Identify the correct way to tag a Spring Boot API method

Which of the following code snippets correctly applies a tag to a single API method in Spring Boot using OpenAPI annotations?

A
@Tag("Orders")
@GetMapping("/orders")
public List<Order> getOrders() { return List.of(); }
B
@Tag(name = "Orders")
@GetMapping("/orders")
public List<Order> getOrders() { return List.of(); }
C
@Tags({@Tag(name = "Orders")})
@GetMapping("/orders")
public List<Order> getOrders() { return List.of(); }
D
@Operation(tags = {"Orders"})
@GetMapping("/orders")
public List<Order> getOrders() { return List.of(); }
Attempts:
2 left
💡 Hint

Remember that @Tag is for classes, while @Operation can tag methods.

🔧 Debug
advanced
2:00remaining
Why does this API tag not appear in Swagger UI?

Given the following controller, the tag 'Inventory' does not show in Swagger UI. What is the most likely cause?

Spring Boot
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";
    }
}
AThe @Tag annotation is placed on the class but the OpenAPI configuration does not scan this package.
BThe @Tag annotation requires a description attribute to show in Swagger UI.
CThe @Tag annotation must be placed on each method, not the class.
DThe @RestController annotation is missing, so the controller is not detected.
Attempts:
2 left
💡 Hint

Check if the package containing the controller is included in the OpenAPI scan.

state_output
advanced
2:00remaining
What is the effect of multiple tags on a single API method?

Consider this Spring Boot API method annotated with multiple tags. What will be the grouping behavior in Swagger UI?

Spring Boot
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";
    }
}
AThe endpoint does not appear in Swagger UI due to multiple tags.
BThe endpoint appears only under the first tag 'Payments' and ignores the second.
CThe endpoint appears under both 'Payments' and 'Transactions' groups in Swagger UI.
DThe endpoint appears under a combined tag named 'Payments, Transactions'.
Attempts:
2 left
💡 Hint

Think about how Swagger UI handles multiple tags on one endpoint.

🧠 Conceptual
expert
2:00remaining
Why use tags to group APIs in Spring Boot projects?

Which of the following is the best explanation for why developers use tags to group APIs in Spring Boot projects with Swagger/OpenAPI?

ATags automatically generate security rules for each group, enforcing access control without extra configuration.
BTags improve API documentation readability by logically grouping related endpoints, making it easier for users to find and understand APIs.
CTags reduce the size of the generated API documentation by hiding untagged endpoints.
DTags are required by Spring Boot to enable REST controllers to function properly.
Attempts:
2 left
💡 Hint

Consider the user experience of API consumers reading the documentation.