InterviewSolution
| 1. |
What is Swagger? Have you implemented it using Spring Boot? |
|
Answer» Swagger is an open-source software framework supported by a large tool ECOSYSTEM that helps developers DESIGN, build, document and use RESTful web services. While most users use the Swagger UI tool to identify Swagger, the Swagger toolkit includes support for automated documentation, code GENERATION and testing. We use annotation @EnableSwagger2 to enable Swagger 2. A docket bean is defined and we get an instance of ApiSelectorBuilder using the select () method. ApiSelectorBuilder we set the Swagger EXPOSED endpoints. After the Docket bean is defined, the select () method returns an instance of ApiSelectorBuilder, which provides a way to control the Swagger exposed endpoints. We configure RequestHandlerSelectors and PathSelectors to select RequestHandlers. Steps to add swagger in spring boot. 1) Add swagger dependency <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency>2) Add swagger configuration in spring class. @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } }3) To enable Enabling Springfox’s Swagger UI, add this dependency <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> |
|