0
0
Spring Bootframework~20 mins

@Parameter and @Schema annotations in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
OpenAPI Annotation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does @Parameter affect API documentation?
Consider a Spring Boot REST controller method with a parameter annotated by @Parameter(description = "User ID"). What effect does this annotation have on the generated OpenAPI documentation?
Spring Boot
public ResponseEntity<User> getUser(@Parameter(description = "User ID") @PathVariable String id) {
    // method body
}
AIt changes the parameter type in the API to a custom object.
BIt automatically validates the parameter value before method execution.
CIt adds a description to the parameter in the OpenAPI docs, helping API consumers understand its purpose.
DIt hides the parameter from the generated API documentation.
Attempts:
2 left
💡 Hint
Think about how @Parameter is used to enhance API documentation metadata.
📝 Syntax
intermediate
2:00remaining
Correct usage of @Schema to define a model property
Which of the following code snippets correctly uses @Schema to specify that a field is required and has a maximum length of 50 characters?
Spring Boot
public class User {
    @Schema(required = true, maxLength = 50)
    private String name;
}
A@Schema(required = true, maxLength = 50)
B@Schema(required = "true", maxLength = 50)
C@Schema(required = true, maxLength = "50")
D@Schema(required = true, maxLength = 50, description = 100)
Attempts:
2 left
💡 Hint
Check the data types of the annotation attributes.
🔧 Debug
advanced
2:00remaining
Why does this @Schema annotation cause a runtime error?
Given the code snippet below, why does the application fail to start? public class Product { @Schema(example = 12345) private String code; }
Spring Boot
public class Product {
    @Schema(example = 12345)
    private String code;
}
AThe field 'code' must be public for @Schema to work.
BThe example attribute expects a String value, but an integer is provided, causing a type mismatch error.
CThe @Schema annotation requires a description attribute to work properly.
DThe example attribute cannot be used on String fields.
Attempts:
2 left
💡 Hint
Check the expected data type for the example attribute in @Schema.
🧠 Conceptual
advanced
2:00remaining
Difference between @Parameter and @Schema annotations
Which statement best describes the difference between @Parameter and @Schema annotations in Spring Boot OpenAPI integration?
A@Parameter and @Schema are interchangeable and serve the same purpose.
B@Parameter validates input values, and @Schema generates API documentation for endpoints.
C@Parameter is only for request bodies, and @Schema is only for response bodies.
D@Parameter is used to describe method parameters in API endpoints, while @Schema describes the structure of data models or properties.
Attempts:
2 left
💡 Hint
Think about what each annotation targets: parameters vs data models.
state_output
expert
3:00remaining
What is the effect of combining @Parameter and @Schema on a method parameter?
Consider this method parameter in a Spring Boot controller: @GetMapping("/items/{id}") public Item getItem( @Parameter(description = "Item identifier") @Schema(example = "42", required = true) @PathVariable String id) { // method body } What will be the combined effect on the generated OpenAPI documentation for this parameter?
Spring Boot
@Parameter(description = "Item identifier")
@Schema(example = "42", required = true)
@PathVariable String id
AThe parameter will have a description, be marked required, and show an example value in the OpenAPI docs.
BThe @Schema annotation will override @Parameter, so only example and required are shown without description.
COnly the @Parameter description is used; @Schema is ignored on method parameters.
DThe parameter will be hidden from the OpenAPI documentation due to conflicting annotations.
Attempts:
2 left
💡 Hint
Both annotations add complementary metadata for API documentation.