0
0
Spring Bootframework~10 mins

SpringDoc OpenAPI setup in Spring Boot - Interactive Code Practice

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

Complete the code to add the SpringDoc OpenAPI dependency in Maven's <dependencies> section.

Spring Boot
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>[1]</artifactId>
    <version>1.7.0</version>
</dependency>
Drag options to blanks, or click blank then click option'
Aspringdoc-openapi-ui
Bspring-boot-starter-web
Cspringdoc-openapi-security
Dspring-boot-starter-data-jpa
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated dependencies like spring-boot-starter-web.
Confusing security or JPA starters with OpenAPI UI.
2fill in blank
medium

Complete the annotation to define OpenAPI documentation metadata in a Spring Boot application.

Spring Boot
@[1]
@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
Drag options to blanks, or click blank then click option'
AEnableOpenApiDoc
BEnableSwagger2
CEnableOpenApi
DOpenAPIDefinition
Attempts:
3 left
💡 Hint
Common Mistakes
Using @EnableSwagger2 which is for older Swagger integration.
Using non-existent annotations like @EnableOpenApi.
3fill in blank
hard

Fix the error in the OpenAPI info bean definition by completing the missing method call.

Spring Boot
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.OpenAPI;

@Bean
public OpenAPI customOpenAPI() {
    return new OpenAPI()
        .info(new Info().title("My API").version([1]));
}
Drag options to blanks, or click blank then click option'
A"1.0"
Bv1
C1.0
D"v1"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing version without quotes causing a compile error.
Using incorrect version format.
4fill in blank
hard

Fill both blanks to configure the OpenAPI bean with a description and contact email.

Spring Boot
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.OpenAPI;

@Bean
public OpenAPI apiInfo() {
    return new OpenAPI()
        .info(new Info()
            .description([1])
            .contact(new Contact().email([2])));
}
Drag options to blanks, or click blank then click option'
A"This is my API"
B"contact@example.com"
C"support@domain.com"
D"API description here"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping description and email values.
Not using quotes around strings.
5fill in blank
hard

Fill all three blanks to create a SpringDoc OpenAPI bean with title, version, and license name.

Spring Boot
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.OpenAPI;

@Bean
public OpenAPI openApiConfig() {
    return new OpenAPI()
        .info(new Info()
            .title([1])
            .version([2])
            .license(new License().name([3])));
}
Drag options to blanks, or click blank then click option'
A"Sample API"
B"2.0"
C"Apache 2.0"
D"My API"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted strings causing errors.
Mixing up license and version values.