Bird
Raised Fist0
Spring Bootframework~20 mins

Swagger UI integration in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Swagger UI Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
Swagger UI Endpoint Accessibility
You have integrated Swagger UI in your Spring Boot application. After running the app, which URL will correctly display the Swagger UI page by default?
Ahttp://localhost:8080/docs
Bhttp://localhost:8080/swagger
Chttp://localhost:8080/swagger-ui.html
Dhttp://localhost:8080/api-docs
Attempts:
2 left
💡 Hint
Swagger UI default path usually ends with .html
📝 Syntax
intermediate
2:00remaining
Correct Swagger Configuration Bean
Which of the following code snippets correctly defines a Swagger configuration bean in Spring Boot using Springfox 3.x?
A
@Bean
public Docket api() {
    return new Docket(DocumentationType.OAS_30)
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.example"))
        .paths(PathSelectors.any())
        .build();
}
B
@Bean
public SwaggerConfig api() {
    return new SwaggerConfig();
}
C
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.any())
        .build();
}
D
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_3)
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.any())
        .build();
}
Attempts:
2 left
💡 Hint
Use the correct DocumentationType enum for OpenAPI 3.0 support
🔧 Debug
advanced
2:00remaining
Swagger UI Not Loading Static Resources
You added Swagger UI to your Spring Boot app, but the UI loads without styles and scripts, showing a broken page. What is the most likely cause?
ASwagger UI requires a separate server to serve static files
BIncorrect controller mapping for Swagger endpoints
CMissing dependency for springfox-swagger-ui in the build file
DSpring Security blocking access to Swagger static resources
Attempts:
2 left
💡 Hint
Check if security settings allow access to /swagger-ui/** and /v3/api-docs/**
🧠 Conceptual
advanced
2:00remaining
Purpose of @OpenAPIDefinition Annotation
What is the main purpose of the @OpenAPIDefinition annotation in a Spring Boot application using springdoc-openapi?
ATo define global metadata like title, version, and description for the OpenAPI documentation
BTo configure security schemes for API authentication
CTo enable Swagger UI endpoint in the application
DTo automatically generate REST controllers from OpenAPI specs
Attempts:
2 left
💡 Hint
Think about what metadata means for documentation
❓ state_output
expert
3:00remaining
Effect of Multiple Docket Beans on Swagger UI
In a Spring Boot app, you define two Docket beans with different group names: apiV1 and apiV2. What will the Swagger UI display when accessed at /swagger-ui.html?
AOnly the apiV1 group APIs are shown by default
BA dropdown to select between apiV1 and apiV2 API groups
CAn error because multiple Docket beans are not supported
DSwagger UI shows combined APIs from both groups without distinction
Attempts:
2 left
💡 Hint
Swagger UI supports multiple API groups via dropdown selection

Practice

(1/5)
1. What is the main purpose of integrating Swagger UI in a Spring Boot project?
easy
A. To improve database performance
B. To generate frontend UI components
C. To handle user authentication automatically
D. To provide a web page that documents and allows testing of your API

Solution

  1. Step 1: Understand Swagger UI's role

    Swagger UI creates a friendly web interface to view and test API endpoints.
  2. Step 2: Compare options

    Only To provide a web page that documents and allows testing of your API describes this purpose; others relate to unrelated features.
  3. Final Answer:

    To provide a web page that documents and allows testing of your API -> Option D
  4. Quick Check:

    Swagger UI = API documentation and testing [OK]
Hint: Swagger UI = API docs + testing page [OK]
Common Mistakes:
  • Confusing Swagger UI with database tools
  • Thinking Swagger handles authentication
  • Assuming Swagger generates frontend code
2. Which dependency should you add to a Spring Boot project to enable Swagger UI with springdoc-openapi?
easy
A. springdoc-openapi-starter-webmvc-ui
B. spring-boot-starter-data-jpa
C. spring-boot-starter-web
D. spring-security-oauth2-client

Solution

  1. Step 1: Identify the correct starter for Swagger UI

    The springdoc-openapi-starter-webmvc-ui dependency enables Swagger UI integration in Spring Boot.
  2. Step 2: Eliminate unrelated dependencies

    Other options relate to web server, database, or security, not Swagger UI.
  3. Final Answer:

    springdoc-openapi-starter-webmvc-ui -> Option A
  4. Quick Check:

    Swagger UI dependency = springdoc-openapi-starter-webmvc-ui [OK]
Hint: Use springdoc-openapi-starter-webmvc-ui for Swagger UI [OK]
Common Mistakes:
  • Adding only spring-boot-starter-web without Swagger
  • Using database or security starters by mistake
  • Forgetting to add any Swagger-related dependency
3. Given a Spring Boot app with springdoc-openapi-starter-webmvc-ui added, what URL should you visit to see the Swagger UI page?
medium
A. /openapi-ui/index.html
B. /api-docs/swagger-ui.html
C. /swagger-ui/index.html
D. /swagger-ui.html

Solution

  1. Step 1: Recall the default Swagger UI path

    springdoc-openapi serves Swagger UI at /swagger-ui/index.html by default.
  2. Step 2: Check other options

    Other URLs are incorrect or outdated paths for Swagger UI.
  3. Final Answer:

    /swagger-ui/index.html -> Option C
  4. Quick Check:

    Swagger UI URL = /swagger-ui/index.html [OK]
Hint: Swagger UI default path ends with /swagger-ui/index.html [OK]
Common Mistakes:
  • Using /swagger-ui.html which is deprecated
  • Confusing API docs JSON URL with UI URL
  • Trying /openapi-ui which is invalid
4. You added springdoc-openapi-starter-webmvc-ui but visiting /swagger-ui/index.html shows 404 error. What is the most likely cause?
medium
A. You did not enable @EnableSwagger2 annotation
B. You need to restart the Spring Boot app after adding dependency
C. You forgot to add spring-boot-starter-web dependency
D. Swagger UI is only available in Spring Boot 3.x and above

Solution

  1. Step 1: Check common setup issues

    After adding a new dependency, the app must be restarted to load it properly.
  2. Step 2: Evaluate other options

    @EnableSwagger2 is not needed with springdoc-openapi; spring-boot-starter-web is usually present; Swagger UI works on Spring Boot 2.x too.
  3. Final Answer:

    You need to restart the Spring Boot app after adding dependency -> Option B
  4. Quick Check:

    Restart app after adding Swagger dependency [OK]
Hint: Restart app after adding dependencies to avoid 404 [OK]
Common Mistakes:
  • Thinking @EnableSwagger2 is required with springdoc-openapi
  • Missing spring-boot-starter-web (usually present)
  • Assuming Swagger UI needs Spring Boot 3 only
5. You want to customize the Swagger UI page title and description in your Spring Boot app using springdoc-openapi. Which approach is correct?
hard
A. Add a bean of type OpenAPI and set info title and description
B. Edit the swagger-ui.html file directly in resources
C. Use @EnableSwagger2 annotation with title parameter
D. Set springdoc.swagger-ui.title property in application.properties

Solution

  1. Step 1: Understand customization with springdoc-openapi

    Customizing title and description is done by defining an OpenAPI bean with Info details.
  2. Step 2: Eliminate incorrect methods

    Editing swagger-ui.html is not recommended; @EnableSwagger2 is for older Swagger versions; springdoc.swagger-ui.title property does not exist.
  3. Final Answer:

    Add a bean of type OpenAPI and set info title and description -> Option A
  4. Quick Check:

    Customize Swagger UI via OpenAPI bean [OK]
Hint: Customize Swagger UI by defining OpenAPI bean [OK]
Common Mistakes:
  • Trying to edit swagger-ui.html manually
  • Using outdated @EnableSwagger2 annotation
  • Expecting a springdoc property for title customization
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard