Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Swagger

susgeorge edited this page Jan 4, 2020 · 1 revision

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:

  1. 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.
io.springfox springfox-swagger2 2.9.2 2. To use Swagger UI, one additional Maven dependency is required: io.springfox springfox-swagger-ui 2.9.2
  1. 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());
    }

  2. To view the documentation, type the following url in the browser : http://localhost:8080/swagger-ui.html

  3. 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.

Clone this wiki locally