Skip to content

Commit

Permalink
Merge pull request #6 from depromeet/feature/swagger
Browse files Browse the repository at this point in the history
docs #5 - Add swagger
  • Loading branch information
junhaesung authored Oct 9, 2019
2 parents d7a8d48 + 47d9ce1 commit 7de5edc
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<properties>
<java.version>1.8</java.version>
<swagger.version>2.9.2</swagger.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -49,6 +50,16 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.depromeet.warmingupteam0backend.dto;

import lombok.Data;

@Data
public class HelloRequest {
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.depromeet.warmingupteam0backend.dto;

import lombok.Data;

@Data
public class HelloResponse {
private String message;
}

0 comments on commit 7de5edc

Please sign in to comment.