Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Swagger UI API integration #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

10 changes: 10 additions & 0 deletions api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
swagger: "2.0"
info:
title: Title
description: Title
version: 1.0.0
host: localhost
schemes:
- https
paths: /

15 changes: 15 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/hellokoding/springboot/Data.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/hellokoding/springboot/DataController.java
Original file line number Diff line number Diff line change
@@ -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) {
}
}
35 changes: 35 additions & 0 deletions app/src/main/java/com/hellokoding/springboot/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -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", "[email protected]"),
"License of API", "API license URL", Collections.emptyList());
}
}