Bird
0
0

In this code snippet:

medium📝 Debug Q7 of 15
Spring Boot - API Documentation
In this code snippet:
@Schema(description = "User's email", example = "user@example.com")
private String email;

The example value does not appear in the generated API docs. What is the most probable reason?
AThe OpenAPI generator version does not support the example attribute
BThe field is private and needs a public getter to be documented
CThe example attribute requires a string literal, but the value is missing quotes
DThe @Schema annotation must be placed on the getter method, not the field
Step-by-Step Solution
Solution:
  1. Step 1: Understand how OpenAPI reads model properties

    OpenAPI generators often require public getters to detect and document private fields.
  2. Step 2: Check other options

    The example value is correctly quoted. Most recent OpenAPI versions support example. @Schema can be on field or getter, but missing getter often causes missing docs.
  3. Final Answer:

    The field is private and needs a public getter to be documented -> Option B
  4. Quick Check:

    Private fields need public getters for docs [OK]
Quick Trick: Add public getters to private fields for documentation [OK]
Common Mistakes:
  • Assuming example attribute is unsupported
  • Placing @Schema only on getter without field
  • Forgetting to add getters for private fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes