Bird
Raised Fist0
Spring Bootframework~20 mins

SpringDoc OpenAPI setup in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
SpringDoc OpenAPI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
1:30remaining
What is the default OpenAPI path after adding SpringDoc dependency?
After adding the SpringDoc OpenAPI dependency to a Spring Boot project, which URL path will serve the OpenAPI JSON specification by default?
A/openapi.json
B/swagger-ui.html
C/v3/api-docs
D/api-docs
Attempts:
2 left
💡 Hint
Think about the default endpoint SpringDoc uses to expose the raw OpenAPI JSON.
📝 Syntax
intermediate
1:30remaining
Which dependency is required for SpringDoc OpenAPI in Maven?
Select the correct Maven dependency snippet to add SpringDoc OpenAPI UI support in a Spring Boot project.
A
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-ui</artifactId>
  <version>1.7.0</version>
</dependency>
B
<dependency>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-ui</artifactId>
  <version>3.0.0</version>
</dependency>
C
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>
D
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-webmvc-core</artifactId>
  <version>1.7.0</version>
</dependency>
Attempts:
2 left
💡 Hint
Look for the artifact that includes UI support for SpringDoc.
🔧 Debug
advanced
2:00remaining
Why does Swagger UI not load after adding SpringDoc?
You added SpringDoc OpenAPI UI dependency and started your Spring Boot app. Accessing /swagger-ui.html returns 404. What is the most likely cause?
AYou forgot to add <code>@EnableSwagger2</code> annotation in your main class.
BThe correct URL is <code>/swagger-ui/index.html</code> or <code>/swagger-ui.html</code> is deprecated in newer SpringDoc versions.
CSpring Boot version is incompatible with SpringDoc and needs to be downgraded.
DYou need to manually create a controller to serve Swagger UI static files.
Attempts:
2 left
💡 Hint
Check the official SpringDoc documentation for the correct Swagger UI URL.
❓ state_output
advanced
1:30remaining
What is the effect of setting springdoc.api-docs.path in application.properties?
If you set springdoc.api-docs.path=/custom-api-docs in your Spring Boot application.properties, what will be the new URL to access the OpenAPI JSON spec?
A/custom-api-docs
B/v3/api-docs
C/swagger-ui/custom-api-docs
D/api-docs/custom
Attempts:
2 left
💡 Hint
This property changes the base path for the OpenAPI JSON output.
🧠 Conceptual
expert
2:30remaining
How does SpringDoc integrate with Spring Boot to generate OpenAPI docs?
Which best describes how SpringDoc generates OpenAPI documentation in a Spring Boot application?
ASpringDoc replaces Spring MVC with a custom web framework to expose API docs.
BSpringDoc requires manual JSON files to be written and served by the application.
CSpringDoc uses compile-time code generation to create static OpenAPI files.
DSpringDoc scans Spring MVC controllers and their annotations at runtime to build the OpenAPI spec dynamically.
Attempts:
2 left
💡 Hint
Think about how SpringDoc uses existing code and annotations to create docs.

Practice

(1/5)
1. What is the main purpose of adding springdoc-openapi-starter-webmvc-ui dependency in a Spring Boot project?
easy
A. To configure logging for the application
B. To enable database connectivity
C. To automatically generate live API documentation for the application
D. To add security features to the application

Solution

  1. Step 1: Understand the role of springdoc-openapi-starter-webmvc-ui

    This dependency integrates SpringDoc OpenAPI with Spring Boot to generate live API docs automatically.
  2. Step 2: Identify the purpose of the dependency

    It provides a user interface and backend support to display API documentation without manual setup.
  3. Final Answer:

    To automatically generate live API documentation for the application -> Option C
  4. Quick Check:

    SpringDoc dependency = live API docs [OK]
Hint: SpringDoc dependency creates live API docs automatically [OK]
Common Mistakes:
  • Confusing it with database or security dependencies
  • Thinking it configures logging
  • Assuming manual doc writing is still needed
2. Which of the following is the correct way to define a basic OpenAPI bean in a Spring Boot application to customize API info?
easy
A. @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().name("API").ver("1.0")); }
B. @Bean public OpenAPI customOpenAPI() { return new OpenAPI().setTitle("API").setVersion("1.0"); }
C. @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info("API", "1.0"); }
D. @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("API").version("1.0")); }

Solution

  1. Step 1: Recall the OpenAPI bean syntax

    The OpenAPI bean requires an Info object with title and version set via methods like title() and version().
  2. Step 2: Compare options with correct method names

    Only @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("API").version("1.0")); } uses correct chaining: new OpenAPI().info(new Info().title("API").version("1.0"))
  3. Final Answer:

    @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("API").version("1.0")); } -> Option D
  4. Quick Check:

    OpenAPI bean uses info(new Info().title().version()) [OK]
Hint: Use Info().title() and .version() methods inside OpenAPI bean [OK]
Common Mistakes:
  • Using incorrect method names like setTitle or info(String, String)
  • Passing strings directly instead of Info object
  • Using non-existent methods like name() or ver()
3. Given this Spring Boot configuration snippet, what will be the URL path to access the Swagger UI documentation?
@SpringBootApplication
public class DemoApplication {
  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }
}

Assuming springdoc-openapi-starter-webmvc-ui is added as dependency and no custom properties are set.
medium
A. /swagger-ui.html
B. /swagger-ui/index.html
C. /api-docs
D. /openapi-ui

Solution

  1. Step 1: Recall default Swagger UI path with SpringDoc

    SpringDoc by default serves Swagger UI at /swagger-ui/index.html
  2. Step 2: Eliminate other options

    /swagger-ui.html is old Swagger path, /api-docs is for JSON docs, /openapi-ui is invalid default
  3. Final Answer:

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

    Default Swagger UI path = /swagger-ui/index.html [OK]
Hint: Swagger UI default path ends with /swagger-ui/index.html [OK]
Common Mistakes:
  • Using old Swagger UI path /swagger-ui.html
  • Confusing JSON docs path with UI path
  • Assuming custom paths without configuration
4. You added the springdoc-openapi-starter-webmvc-ui dependency but when you run your Spring Boot app, the Swagger UI page shows a 404 error. What is the most likely cause?
medium
A. You are trying to access the Swagger UI at the wrong URL
B. You did not include the springdoc-openapi-starter-webmvc-ui dependency correctly
C. You have not defined an OpenAPI bean in your configuration
D. You forgot to add the @SpringBootApplication annotation

Solution

  1. Step 1: Check common reasons for 404 on Swagger UI

    Missing dependency or wrong annotation usually cause app startup errors, not 404 on UI page.
  2. Step 2: Verify URL correctness

    Swagger UI default URL is /swagger-ui/index.html, accessing other URLs like /swagger-ui.html causes 404.
  3. Final Answer:

    You are trying to access the Swagger UI at the wrong URL -> Option A
  4. Quick Check:

    404 on Swagger UI usually means wrong URL [OK]
Hint: Check Swagger UI URL carefully if 404 occurs [OK]
Common Mistakes:
  • Assuming missing OpenAPI bean causes 404
  • Thinking missing @SpringBootApplication causes 404 instead of startup failure
  • Ignoring URL path correctness
5. You want to customize your Spring Boot API documentation with a title "My API" and version "2.0" using SpringDoc. Which code snippet correctly achieves this and ensures the OpenAPI bean is recognized by Spring?
hard
A. @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("My API").version("2.0")); }
B. @Component public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("My API").version("2.0")); }
C. public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("My API").version("2.0")); }
D. @Configuration public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("My API").version("2.0")); }

Solution

  1. Step 1: Ensure the method is a Spring bean

    To register the OpenAPI object, the method must be annotated with @Bean inside a configuration class.
  2. Step 2: Check the code snippet correctness

    @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("My API").version("2.0")); } correctly uses @Bean annotation and returns new OpenAPI().info(new Info().title("My API").version("2.0"))
  3. Final Answer:

    @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info().title("My API").version("2.0")); } -> Option A
  4. Quick Check:

    Use @Bean annotation to register OpenAPI bean [OK]
Hint: Use @Bean annotation on method returning OpenAPI [OK]
Common Mistakes:
  • Omitting @Bean annotation so Spring ignores the method
  • Using @Component or @Configuration on method instead of class
  • Not returning an OpenAPI object with info set
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