Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Added swagger (springfox) Hexlet#8
Browse files Browse the repository at this point in the history
  • Loading branch information
samokisha committed Sep 10, 2019
1 parent dc8c9d6 commit 436eeda
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
24 changes: 19 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@
<description>Demo project for Spring Boot</description>

<properties>
<java.version>12</java.version>
<rest-assured.version>4.1.0</rest-assured.version>
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
<lombok.version>1.18.8</lombok.version>
<h2database.version>1.4.199</h2database.version>
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>

<!-- Code Coverage -->
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
<jacoco-maven-plugin.lines-coverage-ratio>0.8</jacoco-maven-plugin.lines-coverage-ratio>
<jacoco-maven-plugin.methods-coverage-ratio>0.8</jacoco-maven-plugin.methods-coverage-ratio>

<!-- Dependencies versions -->
<java.version>12</java.version>
<rest-assured.version>4.1.0</rest-assured.version>
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
<lombok.version>1.18.8</lombok.version>
<h2database.version>1.4.199</h2database.version>
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>
<springfox-swagger-ui.version>2.9.2</springfox-swagger-ui.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -61,6 +65,16 @@
<version>${h2database.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger-ui.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/io/hexlet/hexletcorrection/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.hexlet.hexletcorrection.config;

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Set;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket fullApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("full-api")
.produces(Set.of(MediaType.APPLICATION_JSON_VALUE))
.select()
.apis(baseControllersPackage())
.paths(PathSelectors.any())
.build();
}

@Bean
public Docket usersApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("users-api")
.produces(Set.of(MediaType.APPLICATION_JSON_VALUE))
.select()
.apis(baseControllersPackage())
.paths(PathSelectors.regex("/users.*"))
.build();
}

@Bean
public Docket correctionsApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("corrections-api")
.produces(Set.of(MediaType.APPLICATION_JSON_VALUE))
.select()
.apis(baseControllersPackage())
.paths(PathSelectors.regex("/corrections.*"))
.build();
}

private Predicate<RequestHandler> baseControllersPackage() {
return RequestHandlerSelectors.basePackage("io.hexlet.hexletcorrection.controller");
}
}

0 comments on commit 436eeda

Please sign in to comment.