From 110b02b91e034e1c483a2a1bb085c6e8a946265f Mon Sep 17 00:00:00 2001 From: Omer Younus Date: Mon, 18 May 2020 14:38:02 -0600 Subject: [PATCH 1/4] adding swager API specification --- api.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 api.yaml 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: / + From 1c5a8a469a76939454cf6e8b8f366e121d8bf488 Mon Sep 17 00:00:00 2001 From: Omer Younus Date: Mon, 18 May 2020 14:38:56 -0600 Subject: [PATCH 2/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a5a9b3a..aeea157 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ - Spring Boot - NGINX - Maven +- Swager API Spec's ## Run - Run command `docker-compose up` From 43d9fa0dc4fe4c3a9294f061cb21006f80cbb699 Mon Sep 17 00:00:00 2001 From: Omer Younus Date: Mon, 18 May 2020 22:50:08 -0600 Subject: [PATCH 3/4] Add Swagger UI dependencies and make it working --- app/pom.xml | 15 ++++++++ .../java/com/hellokoding/springboot/Data.java | 23 ++++++++++++ .../springboot/DataController.java | 30 ++++++++++++++++ .../hellokoding/springboot/SwaggerConfig.java | 35 +++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 app/src/main/java/com/hellokoding/springboot/Data.java create mode 100644 app/src/main/java/com/hellokoding/springboot/DataController.java create mode 100644 app/src/main/java/com/hellokoding/springboot/SwaggerConfig.java 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 From cc0b23d6910b834f389014252874583a57dab342 Mon Sep 17 00:00:00 2001 From: Omer Younus Date: Mon, 18 May 2020 22:53:58 -0600 Subject: [PATCH 4/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index aeea157..a08a0d3 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,7 @@ ## Run - Run command `docker-compose up` - Access to http://localhost/ + +## Swagger2 UI +- Access here http://localhost/swagger-ui.html +