What is Swagger UI used for in a Spring Boot project?
Swagger UI provides a visual interface to explore and test REST APIs directly from the browser, making it easier to understand and interact with the API endpoints.
Click to reveal answer
beginner
Which dependency is commonly added to a Spring Boot project to enable Swagger UI?
The 'springdoc-openapi-ui' dependency is commonly used to integrate Swagger UI with Spring Boot, providing automatic API documentation and UI.
Click to reveal answer
beginner
How do you access Swagger UI once integrated into a Spring Boot application?
After integration, Swagger UI is usually accessible at the URL path '/swagger-ui.html' or '/swagger-ui/index.html' in the running application.
Click to reveal answer
beginner
What annotation is used to mark a Spring Boot controller to be included in Swagger documentation?
The '@RestController' annotation marks a class as a REST controller, and Swagger automatically includes its endpoints in the documentation.
Click to reveal answer
intermediate
How can you customize the API information shown in Swagger UI in Spring Boot?
You can customize API info by creating a bean of type 'OpenAPI' and setting details like title, description, version, and contact information.
Click to reveal answer
Which dependency should you add to a Spring Boot project to enable Swagger UI?
Aorg.springframework.boot:spring-boot-starter-web
Borg.hibernate:hibernate-core
Corg.apache.commons:commons-lang3
Dorg.springdoc:springdoc-openapi-ui
✗ Incorrect
The 'springdoc-openapi-ui' dependency integrates Swagger UI with Spring Boot for API documentation.
What URL path typically shows the Swagger UI page in a Spring Boot app?
A/api-docs
B/swagger-ui.html
C/home
D/login
✗ Incorrect
Swagger UI is usually accessible at '/swagger-ui.html' or '/swagger-ui/index.html' after integration.
Which annotation is used to define a REST controller for Swagger to document?
A@RestController
B@Component
C@Entity
D@Service
✗ Incorrect
The '@RestController' annotation marks a class as a REST API controller, which Swagger documents.
How can you customize the API title and description in Swagger UI?
ABy creating an OpenAPI bean with custom info
BBy editing application.properties
CBy changing the main class name
DBy adding @CustomSwagger annotation
✗ Incorrect
Creating an OpenAPI bean lets you set custom API info like title and description.
What is the main benefit of integrating Swagger UI in Spring Boot?
AFaster database queries
BImproved security
CVisual API documentation and testing
DAutomatic UI themes
✗ Incorrect
Swagger UI provides a visual interface to explore and test APIs easily.
Explain how to add Swagger UI to a Spring Boot project and access the API documentation.
Think about dependencies and the URL path for Swagger UI.
You got /3 concepts.
Describe how to customize the API information shown in Swagger UI in Spring Boot.
Customization involves creating a configuration bean.
You got /3 concepts.
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
Step 1: Understand Swagger UI's role
Swagger UI creates a friendly web interface to view and test API endpoints.
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.
Final Answer:
To provide a web page that documents and allows testing of your API -> Option D
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
Step 1: Identify the correct starter for Swagger UI
The springdoc-openapi-starter-webmvc-ui dependency enables Swagger UI integration in Spring Boot.
Step 2: Eliminate unrelated dependencies
Other options relate to web server, database, or security, not Swagger UI.