0
0
Spring Bootframework~20 mins

Generating client code from spec in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spring Boot Client Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of the generated client method call?

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"}?

Spring Boot
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
ANull because response body is not parsed
BUser object with id=5 and name='Alice'
CException thrown due to missing headers
DUser object with id=0 and name=null
Attempts:
2 left
💡 Hint

Think about how restTemplate.getForEntity works and what getBody() returns.

📝 Syntax
intermediate
2:00remaining
Which option correctly configures OpenAPI Generator for Spring Boot client code?

You want to generate a Spring Boot client from an OpenAPI spec using OpenAPI Generator CLI. Which command is correct?

Aopenapi-generator-cli generate -i api.yaml -g java-spring -o ./client
Bopenapi-generator-cli generate -i api.yaml -g springboot -o ./client
Copenapi-generator-cli generate -i api.yaml -g spring -o ./client
Dopenapi-generator-cli generate -i api.yaml -g springboot-client -o ./client
Attempts:
2 left
💡 Hint

Check the official generator names for Spring Boot clients.

🔧 Debug
advanced
2:30remaining
Why does the generated Spring Boot client fail with 404 on valid endpoint?

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?

AThe server does not support GET requests
BThe client is missing authentication headers
CThe base URL in the client is incorrect or missing
DThe User class is not annotated with @Entity
Attempts:
2 left
💡 Hint

Think about what differs between the client and curl calls.

state_output
advanced
2:00remaining
What is the state of the client after calling an asynchronous generated method?

A Spring Boot client generated method getUserByIdAsync(5) returns a CompletableFuture<User>. After calling it, what is the state of the future immediately?

Spring Boot
CompletableFuture<User> future = client.getUserByIdAsync(5);
// Immediately after this line
AThe future is not done and will complete later with the User
BThe future is already completed with the User
CThe future is completed exceptionally with an error
DThe future is null
Attempts:
2 left
💡 Hint

Consider how asynchronous calls behave in Java.

🧠 Conceptual
expert
3:00remaining
Which statement about generating Spring Boot clients from OpenAPI specs is true?

Choose the correct statement about generating Spring Boot client code from OpenAPI specifications.

AGenerated clients do not support authentication mechanisms
BGenerated clients always include UI components for API testing
COpenAPI Generator only supports server code generation, not clients
DThe generated client code can be customized by modifying templates before generation
Attempts:
2 left
💡 Hint

Think about the flexibility of OpenAPI Generator.