Given a Spring Boot generated client from an OpenAPI spec, what will be the output when calling getUserById(5) if the server returns {"id":5,"name":"Alice"}?
public User getUserById(int id) { // Generated client code ResponseEntity<User> response = restTemplate.getForEntity("/users/{id}", User.class, id); return response.getBody(); } // Assume User class has fields id and name with getters
Think about how restTemplate.getForEntity works and what getBody() returns.
The generated client uses RestTemplate to call the API and maps the JSON response to a User object. The getBody() method returns the deserialized User instance with the correct fields.
You want to generate a Spring Boot client from an OpenAPI spec using OpenAPI Generator CLI. Which command is correct?
Check the official generator names for Spring Boot clients.
The correct generator name for Spring Boot client code is java-spring. Other options are invalid generator names and will cause errors.
You generated a Spring Boot client from an OpenAPI spec. Calling getUserById(10) returns 404, but the server endpoint exists and works via curl. What is the likely cause?
Think about what differs between the client and curl calls.
A common cause is the client not having the correct base URL configured, so requests go to the wrong address and get 404. Authentication or entity annotations do not cause 404 here.
A Spring Boot client generated method getUserByIdAsync(5) returns a CompletableFuture<User>. After calling it, what is the state of the future immediately?
CompletableFuture<User> future = client.getUserByIdAsync(5);
// Immediately after this lineConsider how asynchronous calls behave in Java.
Immediately after calling the async method, the CompletableFuture is not done yet because the HTTP call is still in progress. It will complete later when the response arrives.
Choose the correct statement about generating Spring Boot client code from OpenAPI specifications.
Think about the flexibility of OpenAPI Generator.
OpenAPI Generator allows customizing client code by editing or creating templates. It supports both server and client generation, and clients can include authentication support. UI components are not generated by default.