0
0
Spring Bootframework~10 mins

Swagger UI integration 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 Swagger UI dependency in Maven's <dependencies> section.

Spring Boot
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>[1]</artifactId>
    <version>3.0.0</version>
</dependency>
Drag options to blanks, or click blank then click option'
Aspringfox-swagger-ui
Bspring-boot-starter-web
Cspringfox-swagger2
Dspring-boot-starter-actuator
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'springfox-swagger2' which is for Swagger core but not UI.
Using unrelated Spring Boot starters.
2fill in blank
medium

Complete the code to enable Swagger UI in a Spring Boot configuration class.

Spring Boot
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.[1]("com.example"))
                .paths(PathSelectors.any())
                .build();
    }
}
Drag options to blanks, or click blank then click option'
AbasePackage
Bany
Cnone
Dregex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'any' which selects all APIs without filtering.
Using 'regex' which requires a regex pattern, not a package string.
3fill in blank
hard

Fix the error in the Swagger UI URL path to access the documentation.

Spring Boot
http://localhost:8080/[1]
Drag options to blanks, or click blank then click option'
Aswagger-ui
Bapi-docs
Cv2/api-docs
Dswagger-ui.html
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/swagger-ui' which is not the full path for the UI page.
Using '/v2/api-docs' which is the JSON endpoint, not the UI.
4fill in blank
hard

Fill both blanks to configure Swagger to only document APIs with paths starting with '/api'.

Spring Boot
return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.example"))
        .paths(PathSelectors.[1]("[2]"))
        .build();
Drag options to blanks, or click blank then click option'
Aant
Bregex
C/api/**
D/api/.*
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'regex' with an ant-style pattern.
Using 'ant' with a regex pattern.
5fill in blank
hard

Fill all three blanks to customize the Swagger API info with title, description, and version.

Spring Boot
return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(new ApiInfoBuilder()
            .title("[1]")
            .description("[2]")
            .version("[3]")
            .build())
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.any())
        .build();
Drag options to blanks, or click blank then click option'
AMy API
BThis API provides user data
C1.0.0
DSwagger UI
Attempts:
3 left
💡 Hint
Common Mistakes
Putting unrelated strings in the wrong fields.
Leaving version empty or using non-semantic versions.