Complete the code to add a simple REST controller in 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]; } }
The method should return a string literal with quotes to send as the HTTP response body.
Complete the code to add OpenAPI documentation annotation for the controller method.
import io.swagger.v3.oas.annotations.Operation; @RestController public class HelloController { @GetMapping("/hello") @Operation(summary = [1]) public String sayHello() { return "Hello, World!"; } }
The summary attribute requires a string literal describing the API operation.
Fix the error in the code to correctly document the response code in OpenAPI annotation.
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!"; } }
The responseCode attribute expects a string literal representing the HTTP status code.
Fill both blanks to create a Map of endpoint names to their descriptions for API documentation.
Map<String, String> apiDocs = Map.of(
[1], [2]
);The Map.of method takes key-value pairs as arguments. The key is the endpoint path, and the value is its description.
Fill all three blanks to define a Spring Boot REST controller with OpenAPI tags and summary.
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!"; } }
The @Tag annotation needs a name and description as string literals. The @Operation summary is also a string literal describing the method.