From 47d9ce1d7df892f18582bd46ab6f6cd41007b21e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=84=ED=95=B4=EC=84=B1?= Date: Wed, 9 Oct 2019 14:55:34 +0900 Subject: [PATCH] docs #5 - Add swagger --- pom.xml | 11 +++++++++ .../config/SwaggerConfig.java | 23 +++++++++++++++++++ .../controller/HelloController.java | 21 +++++++++++++++++ .../dto/HelloRequest.java | 8 +++++++ .../dto/HelloResponse.java | 8 +++++++ 5 files changed, 71 insertions(+) create mode 100644 src/main/java/com/depromeet/warmingupteam0backend/config/SwaggerConfig.java create mode 100644 src/main/java/com/depromeet/warmingupteam0backend/controller/HelloController.java create mode 100644 src/main/java/com/depromeet/warmingupteam0backend/dto/HelloRequest.java create mode 100644 src/main/java/com/depromeet/warmingupteam0backend/dto/HelloResponse.java diff --git a/pom.xml b/pom.xml index d61e81d..b365367 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ 1.8 + 2.9.2 @@ -49,6 +50,16 @@ spring-boot-starter-test test + + io.springfox + springfox-swagger2 + ${swagger.version} + + + io.springfox + springfox-swagger-ui + ${swagger.version} + diff --git a/src/main/java/com/depromeet/warmingupteam0backend/config/SwaggerConfig.java b/src/main/java/com/depromeet/warmingupteam0backend/config/SwaggerConfig.java new file mode 100644 index 0000000..6f3873c --- /dev/null +++ b/src/main/java/com/depromeet/warmingupteam0backend/config/SwaggerConfig.java @@ -0,0 +1,23 @@ +package com.depromeet.warmingupteam0backend.config; + +import com.google.common.base.Predicates; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +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; + +@EnableSwagger2 +@Configuration +public class SwaggerConfig { + @Bean + public Docket docket() { + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(Predicates.not(PathSelectors.regex("/error.*"))) // basic error controller + .build(); + } +} diff --git a/src/main/java/com/depromeet/warmingupteam0backend/controller/HelloController.java b/src/main/java/com/depromeet/warmingupteam0backend/controller/HelloController.java new file mode 100644 index 0000000..a026b72 --- /dev/null +++ b/src/main/java/com/depromeet/warmingupteam0backend/controller/HelloController.java @@ -0,0 +1,21 @@ +package com.depromeet.warmingupteam0backend.controller; + +import com.depromeet.warmingupteam0backend.dto.HelloRequest; +import com.depromeet.warmingupteam0backend.dto.HelloResponse; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class HelloController { + @PostMapping("/hello") + public HelloResponse sayHello(@RequestBody HelloRequest helloRequest) { + String name = helloRequest.getName(); + + HelloResponse helloResponse = new HelloResponse(); + helloResponse.setMessage("Hello, " + name + "!"); + return helloResponse; + } +} diff --git a/src/main/java/com/depromeet/warmingupteam0backend/dto/HelloRequest.java b/src/main/java/com/depromeet/warmingupteam0backend/dto/HelloRequest.java new file mode 100644 index 0000000..53d8596 --- /dev/null +++ b/src/main/java/com/depromeet/warmingupteam0backend/dto/HelloRequest.java @@ -0,0 +1,8 @@ +package com.depromeet.warmingupteam0backend.dto; + +import lombok.Data; + +@Data +public class HelloRequest { + private String name; +} diff --git a/src/main/java/com/depromeet/warmingupteam0backend/dto/HelloResponse.java b/src/main/java/com/depromeet/warmingupteam0backend/dto/HelloResponse.java new file mode 100644 index 0000000..490c9fd --- /dev/null +++ b/src/main/java/com/depromeet/warmingupteam0backend/dto/HelloResponse.java @@ -0,0 +1,8 @@ +package com.depromeet.warmingupteam0backend.dto; + +import lombok.Data; + +@Data +public class HelloResponse { + private String message; +}