Bird
0
0

Given this Spring Boot controller snippet with Springdoc enabled, what will the generated API docs show for the endpoint?

medium📝 component behavior Q13 of 15
Spring Boot - API Documentation
Given this Spring Boot controller snippet with Springdoc enabled, what will the generated API docs show for the endpoint?
@RestController
@RequestMapping("/api")
public class UserController {
  @GetMapping("/users/{id}")
  public User getUser(@PathVariable String id) {
    return new User(id, "Alice");
  }
}
AAn endpoint POST /api/users that creates a new user.
BAn endpoint GET /users without path variables.
CNo endpoint will be documented because @GetMapping is missing.
DAn endpoint GET /api/users/{id} that returns a User object with id and name.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the controller mapping

    The class maps to /api, and the method maps GET requests to /users/{id} with a path variable.
  2. Step 2: Understand Springdoc output

    Springdoc generates docs showing GET /api/users/{id} returning a User object with id and name fields.
  3. Final Answer:

    An endpoint GET /api/users/{id} that returns a User object with id and name. -> Option D
  4. Quick Check:

    GET /api/users/{id} documented with User return [OK]
Quick Trick: Check @RequestMapping + @GetMapping paths for docs URL [OK]
Common Mistakes:
  • Confusing GET with POST method
  • Ignoring path variables in URL
  • Assuming no docs generated without extra config

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes