-
Notifications
You must be signed in to change notification settings - Fork 1
Swagger
It is important to have proper documentation for the back-end APIs. We use Swagger 2 to document a Spring REST web service.Below are the steps to integrate Swagger in a springboot app:
- We will use the Springfox implementation of the Swagger specification. To add it to our Maven project, we need a dependency in the pom.xml file.
-
Next we integrate Swagger into our Java Project. We create a class ‘SwaggerConfig’ under edu.uga.ccrc.config package. This class is annotated with @Configuration and @EnableSwagger2. Swagger 2 is enabled through the @EnableSwagger2 annotation. Swagger configuration mainly centers around the Docket Bean:
@Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("edu.uga.ccrc.controller"))
.paths(PathSelectors.any())
.build() .apiInfo(apiInfo());
} -
To view the documentation, type the following url in the browser : http://localhost:8080/swagger-ui.html
-
Documentation of a rest api can be done through annotations. @ApiOperation describes the operation of a web-service and @ApiResponse describes the possible response of a web-service.Check the DatasetController to view the annotation usage.