0
0
Spring Bootframework~10 mins

Why API docs matter in Spring Boot - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a simple REST controller in Spring Boot.

Spring Boot
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String sayHello() {
        return [1];
    }
}
Drag options to blanks, or click blank then click option'
ASystem.out.println("Hello, World!")
B"Hello, World!"
Creturn "Hello, World!";
DHello, World!
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Using print statements instead of return
2fill in blank
medium

Complete the code to add OpenAPI documentation annotation for the controller method.

Spring Boot
import io.swagger.v3.oas.annotations.Operation;

@RestController
public class HelloController {
    @GetMapping("/hello")
    @Operation(summary = [1])
    public String sayHello() {
        return "Hello, World!";
    }
}
Drag options to blanks, or click blank then click option'
A"Greeting endpoint"
BReturns a greeting message
C"Hello endpoint"
D"Returns a greeting message"
Attempts:
3 left
💡 Hint
Common Mistakes
Missing quotes around the summary
Using plain text without quotes
3fill in blank
hard

Fix the error in the code to correctly document the response code in OpenAPI annotation.

Spring Boot
import io.swagger.v3.oas.annotations.responses.ApiResponse;

@RestController
public class HelloController {
    @GetMapping("/hello")
    @ApiResponse(responseCode = [1], description = "Successful greeting")
    public String sayHello() {
        return "Hello, World!";
    }
}
Drag options to blanks, or click blank then click option'
A200
BHttpStatus.OK
C"200"
DOK
Attempts:
3 left
💡 Hint
Common Mistakes
Using integer 200 without quotes
Using enum constants instead of string
4fill in blank
hard

Fill both blanks to create a Map of endpoint names to their descriptions for API documentation.

Spring Boot
Map<String, String> apiDocs = Map.of(
    [1], [2]
);
Drag options to blanks, or click blank then click option'
A"/hello"
B"Returns greeting message"
C"/goodbye"
D"Returns farewell message"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping key and value
Missing quotes around strings
5fill in blank
hard

Fill all three blanks to define a Spring Boot REST controller with OpenAPI tags and summary.

Spring Boot
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;

@RestController
@Tag(name = [1], description = [2])
public class GreetingController {
    @GetMapping("/greet")
    @Operation(summary = [3])
    public String greet() {
        return "Greetings!";
    }
}
Drag options to blanks, or click blank then click option'
A"Greeting API"
B"API for greeting endpoints"
C"Returns a greeting message"
D"GreetingController"
Attempts:
3 left
💡 Hint
Common Mistakes
Using class names instead of descriptive strings
Missing quotes around strings