What is the purpose of the @Parameter annotation in Spring Boot?
The @Parameter annotation is used to describe and document parameters of API endpoints, helping tools like Swagger generate clear API documentation.
Click to reveal answer
beginner
How does the @Schema annotation help in API development?
The @Schema annotation defines metadata for model properties, such as descriptions, example values, and data types, improving API documentation clarity.
Click to reveal answer
beginner
Which annotation would you use to add a description to a query parameter in a REST API?
You would use the @Parameter annotation to add a description to a query parameter.
Click to reveal answer
intermediate
Can @Schema be used on method parameters or only on model fields?
While @Schema is mainly used on model fields to describe data properties, it can also be used on method parameters to provide schema details.
Click to reveal answer
intermediate
What is the benefit of using @Parameter and @Schema annotations together in Spring Boot APIs?
Using both annotations together improves API documentation by clearly describing parameters and data models, making APIs easier to understand and use.
Click to reveal answer
What does the @Parameter annotation primarily describe?
ADatabase schema
BAPI endpoint parameters
CUI components
DLogging configuration
✗ Incorrect
The @Parameter annotation is used to describe parameters of API endpoints.
Which annotation helps define example values for API model properties?
A@Schema
B@Autowired
C@RequestMapping
D@Parameter
✗ Incorrect
@Schema allows setting example values and descriptions for model properties.
Where would you typically place the @Schema annotation?
AOn API endpoint methods
BOn service classes
COn model class fields
DOn configuration files
✗ Incorrect
@Schema is usually placed on model fields to describe data properties.
Which annotation improves generated Swagger UI documentation for parameters?
A@Parameter
B@Entity
C@Component
D@Service
✗ Incorrect
@Parameter enhances Swagger UI by describing API parameters.
Can @Parameter be used to describe header parameters in an API?
AOnly for path variables
BNo
COnly for body parameters
DYes
✗ Incorrect
@Parameter can describe any API parameter including headers.
Explain how @Parameter and @Schema annotations help improve API documentation in Spring Boot.
Think about how these annotations add descriptions and examples.
You got /3 concepts.
Describe a scenario where you would use both @Parameter and @Schema annotations together in a Spring Boot REST controller.
Consider an endpoint with query parameters and a JSON response body.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the @Parameter annotation in Spring Boot APIs?
easy
A. To describe method parameters for API documentation
B. To define database entity fields
C. To configure security roles
D. To handle exceptions globally
Solution
Step 1: Understand the role of @Parameter
The @Parameter annotation is used to add descriptive information about method parameters in API endpoints.
Step 2: Differentiate from other annotations
It is not used for database, security, or exception handling but specifically for API documentation clarity.
Final Answer:
To describe method parameters for API documentation -> Option A
Quick Check:
@Parameter describes API method parameters = D [OK]
Hint: Remember: @Parameter is for method parameter docs [OK]
Common Mistakes:
Confusing @Parameter with @Schema for data models
Thinking @Parameter manages security or exceptions
Using @Parameter for database field mapping
2. Which of the following is the correct way to add a description to a method parameter using @Parameter?
easy
A. @Parameter(value = "User ID") String userId
B. @Parameter(description = "User ID") String userId
C. @Parameter(desc = "User ID") String userId
D. @Parameter(text = "User ID") String userId
Solution
Step 1: Recall the correct attribute name
The @Parameter annotation uses the attribute description to add text about the parameter.
Step 2: Verify syntax correctness
Only @Parameter(description = "User ID") String userId uses description correctly; others use invalid attribute names.
Final Answer:
@Parameter(description = "User ID") String userId -> Option B
Quick Check:
@Parameter uses description attribute = A [OK]
Hint: Use description= for @Parameter text, not value or desc [OK]
Common Mistakes:
Using 'value' instead of 'description' attribute
Using non-existent attributes like 'desc' or 'text'
Omitting the attribute name entirely
3. Given the code snippet:
@Parameter(description = "User's age", required = true) int age
What effect does the required = true have in API documentation?
medium
A. Marks the parameter as mandatory in the API docs
B. Sets a default value for the parameter
C. Makes the parameter optional
D. Hides the parameter from the API docs
Solution
Step 1: Understand the required attribute
The required = true flag indicates that the parameter must be provided by the API caller.
Step 2: Effect on API documentation
This makes the parameter appear as mandatory in generated API docs, guiding users to supply it.
Final Answer:
Marks the parameter as mandatory in the API docs -> Option A
Quick Check:
required=true means mandatory parameter = B [OK]
Hint: required=true means parameter must be provided [OK]
Common Mistakes:
Thinking required=true sets default values
Assuming it hides the parameter
Confusing required=true with optional parameters
4. Identify the error in this usage of @Schema annotation:
A. The annotation must be placed on the getter method, not the field
B. The description attribute is missing
C. The required attribute should be a boolean, not a string
D. The email field must be public for @Schema to work
Solution
Step 1: Check attribute types in @Schema
The required attribute expects a boolean value, not a string.
Step 2: Identify the error in the code
Using required = "true" is incorrect; it should be required = true without quotes.
Final Answer:
The required attribute should be a boolean, not a string -> Option C
Quick Check:
@Schema required must be boolean, not string = C [OK]
Hint: Use true/false without quotes for boolean attributes [OK]
Common Mistakes:
Putting boolean values in quotes
Assuming @Schema only works on methods
Thinking field visibility affects @Schema
5. You want to document a complex API model field that can be null but has a maximum length of 50 characters. Which @Schema annotation usage is correct?