diff --git a/README.md b/README.md index a5a9b3a..a08a0d3 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,12 @@ - Spring Boot - NGINX - Maven +- Swager API Spec's ## Run - Run command `docker-compose up` - Access to http://localhost/ + +## Swagger2 UI +- Access here http://localhost/swagger-ui.html + diff --git a/api.yaml b/api.yaml new file mode 100644 index 0000000..e777401 --- /dev/null +++ b/api.yaml @@ -0,0 +1,10 @@ +swagger: "2.0" +info: + title: Title + description: Title + version: 1.0.0 +host: localhost +schemes: + - https +paths: / + diff --git a/app/pom.xml b/app/pom.xml index 7505b86..330f3d1 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -19,6 +19,21 @@ org.springframework.boot spring-boot-starter-freemarker + + org.springframework.boot + spring-boot-starter-web + + + io.springfox + springfox-swagger2 + 2.4.0 + + + + io.springfox + springfox-swagger-ui + 2.4.0 + diff --git a/app/src/main/java/com/hellokoding/springboot/Data.java b/app/src/main/java/com/hellokoding/springboot/Data.java new file mode 100644 index 0000000..7e22b9a --- /dev/null +++ b/app/src/main/java/com/hellokoding/springboot/Data.java @@ -0,0 +1,23 @@ +package com.hellokoding.springboot; + +public class Data { + + private int id; + private String text; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/hellokoding/springboot/DataController.java b/app/src/main/java/com/hellokoding/springboot/DataController.java new file mode 100644 index 0000000..2127763 --- /dev/null +++ b/app/src/main/java/com/hellokoding/springboot/DataController.java @@ -0,0 +1,30 @@ +package com.hellokoding.springboot; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +public class DataController { + + @RequestMapping(method = RequestMethod.GET, value = "/data/{id}") + public Data getData(@PathVariable Integer id) { + return new Data(); + } + + @RequestMapping(method = RequestMethod.POST, value = "/data") + public Data saveData(Data data) { + return data; + } + + @RequestMapping(method = RequestMethod.PUT, value = "/data/{id}") + public Data updateData(@PathVariable Integer id, Data data) { + return data; + } + + @RequestMapping(method = RequestMethod.DELETE, value = "/data/{id}") + public void deleteData(@PathVariable Integer id) { + } +} \ No newline at end of file diff --git a/app/src/main/java/com/hellokoding/springboot/SwaggerConfig.java b/app/src/main/java/com/hellokoding/springboot/SwaggerConfig.java new file mode 100644 index 0000000..3c6e8d3 --- /dev/null +++ b/app/src/main/java/com/hellokoding/springboot/SwaggerConfig.java @@ -0,0 +1,35 @@ +package com.hellokoding.springboot; + +import com.google.common.base.Predicates; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage("org.springframework.boot")) + .paths(PathSelectors.ant("/api/*")) + .build() + .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + return new ApiInfo( + "My REST API", + "Some custom description of API.", + "API TOS", + "Terms of service", + new Contact("Omer Younus", "www.example.com", "myeaddress@company.com"), + "License of API", "API license URL", Collections.emptyList()); + } +} \ No newline at end of file