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

Feature/19 gateway centralized swagger UI #83

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
8 changes: 8 additions & 0 deletions bill/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ dependencies {
implementation project(':common')
annotationProcessor project(':common')

// Spring dependencies
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'

// Eureka Service Registry
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:3.1.3'

// Open Api UI dependency
implementation 'org.springdoc:springdoc-openapi-ui:1.6.9'
}
2 changes: 2 additions & 0 deletions bill/src/main/java/com/tungstun/bill/BillApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.kafka.annotation.EnableKafka;

@SpringBootApplication
@ComponentScan("com.tungstun")
@EnableKafka
@EnableEurekaClient
public class BillApplication {
public static void main(String[] args) {
SpringApplication.run(BillApplication.class, args);
Expand Down
63 changes: 41 additions & 22 deletions bill/src/main/java/com/tungstun/bill/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
package com.tungstun.bill.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.annotations.OpenAPI31;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.SpecVersion;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.tags.Tag;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@OpenAPI31
@OpenAPIDefinition(
info = @Info(
title = "bartap Backend Api - Bill",
description = "Bill API of the bartap Backend API microservice cluster containing bill functionality",
version = "1.0",
contact = @Contact(
name = "Tungstun",
url = "https://github.com/tungstun-ict",
email = "[email protected]"
)
),
tags = {
@Tag(name = "Bill", description = "Functionality based around the Bill"),
@Tag(name = "Order", description = "Functionality based around the Order and Order History"),
}
)
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI gatewayOpenApi(@Value("${GATEWAY_URL:}") String gatewayUrl) {
OpenAPI openApi = new OpenAPI(SpecVersion.V31)
.info(new Info()
.title("bartap Backend Api - Bill")
.description("Bill API of the bartap Backend API microservice cluster containing bill functionality")
.version("1.0")
.contact(new Contact()
.name("Tungstun")
.url("https://github.com/tungstun-ict")
.email("[email protected]")))
.addTagsItem(new Tag().name("Bill").description("Functionality based around the Bill"))
.addTagsItem(new Tag().name("Order").description("Functionality based around the Order"))
.schemaRequirement("Bearer", new SecurityScheme()
.name("Bearer")
.description("Authorization using Bearer JWT")
.type(SecurityScheme.Type.HTTP)
.in(SecurityScheme.In.HEADER)
.scheme("bearer")
.bearerFormat("JWT"));

if (gatewayUrl != null) {
openApi.addServersItem(new Server()
.description("Gateway Url")
.url(gatewayUrl)
);
}

return openApi;
}
}
3 changes: 2 additions & 1 deletion bill/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#JWT variables
JWT_SECRET=lets-make-a-bar-application-and-use-this-as-a-session-token-secret
JWT_ISSUER=bartap-security-service

#Database properties and variables
JDBC_DATABASE_URL=jdbc:h2:mem:test;MODE=PostgreSQL;DB_CLOSE_DELAY=-1
DRIVER_CLASS_NAME=org.h2.Driver
#Gateway url
GATEWAY_URL=http://localhost:8081${server.servlet.context-path}
7 changes: 5 additions & 2 deletions bill/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Standard configurations
spring.application.name=bartap-bill
spring.application.name=bill
spring.profiles.active=dev
server.port=8083
server.servlet.context-path=/api
Expand All @@ -15,7 +15,10 @@ spring.datasource.driverClassName=${DRIVER_CLASS_NAME}
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}

# Kafka
spring.kafka.bootstrap-servers=${BOOTSTRAP_SERVERS:localhost:9092}
spring.kafka.consumer.auto-offset-reset=earliest
# Eureka Registry
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
15 changes: 7 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@ subprojects {
apply plugin: 'jacoco'

dependencies {
// Basic Spring dependencies (used by most)
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.hibernate.validator:hibernate-validator:6.1.5.Final'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"

// In-memory database for easy local spin up and testing
implementation 'com.h2database:h2'
implementation 'io.swagger.core.v3:swagger-core:2.2.1'

// Spring Kafka
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.springframework.kafka:spring-kafka-test'
testImplementation 'org.springframework.kafka:spring-kafka-test'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'io.projectreactor:reactor-test'
}

task prepareKotlinBuildScriptModel {}
task wrapper {}

Expand Down
10 changes: 9 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ repositories {
}

dependencies {
// Spring dependencies
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"

// auth0
implementation 'com.auth0:java-jwt:3.19.2'

// Google dependencies
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.49'

// Reflections library
implementation 'org.reflections:reflections:0.10.2'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ private void loadTimezoneConfig() {
public void setTimezone(String timezone) {
this.timezone = timezone;
}

public String getTimezone() {
return timezone;
}
}
8 changes: 8 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ dependencies {
implementation project(':common')
annotationProcessor project(':common')

// Spring dependencies
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'

// Eureka Service Registry
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:3.1.3'

// Open Api UI dependency
implementation 'org.springdoc:springdoc-openapi-ui:1.6.9'
}

2 changes: 2 additions & 0 deletions core/src/main/java/com/tungstun/core/CoreApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.kafka.annotation.EnableKafka;

@SpringBootApplication
@ComponentScan("com.tungstun")
@EnableKafka
@EnableEurekaClient
public class CoreApplication {
public static void main(String[] args) {
SpringApplication.run(CoreApplication.class, args);
Expand Down
63 changes: 41 additions & 22 deletions core/src/main/java/com/tungstun/core/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
package com.tungstun.core.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.annotations.OpenAPI31;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.SpecVersion;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.tags.Tag;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@OpenAPI31
@OpenAPIDefinition(
info = @Info(
title = "bartap Backend Api - Core",
description = "Core API of the bartap Backend API microservice cluster containing bar and session functionality",
version = "1.0",
contact = @Contact(
name = "Tungstun",
url = "https://github.com/tungstun-ict",
email = "[email protected]"
)
),
tags = {
@Tag(name = "Bar", description = "Functionality based around the Bar"),
@Tag(name = "Session", description = "Functionality based around the Session")
}
)
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI gatewayOpenApi(@Value("${GATEWAY_URL:}") String gatewayUrl) {
OpenAPI openApi = new OpenAPI(SpecVersion.V31)
.info(new Info()
.title("bartap Backend Api - Core")
.description("Core API of the bartap Backend API microservice cluster containing bar and session functionality")
.version("1.0")
.contact(new Contact()
.name("Tungstun")
.url("https://github.com/tungstun-ict")
.email("[email protected]")))
.addTagsItem(new Tag().name("Bar").description("Functionality based around the Bar"))
.addTagsItem(new Tag().name("Session").description("Functionality based around the Session"))
.schemaRequirement("Bearer", new SecurityScheme()
.name("Bearer")
.description("Authorization using Bearer JWT")
.type(SecurityScheme.Type.HTTP)
.in(SecurityScheme.In.HEADER)
.scheme("bearer")
.bearerFormat("JWT"));

if (gatewayUrl != null) {
openApi.addServersItem(new Server()
.description("Gateway Url")
.url(gatewayUrl)
);
}

return openApi;
}
}
3 changes: 2 additions & 1 deletion core/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#JWT variables
JWT_SECRET=lets-make-a-bar-application-and-use-this-as-a-session-token-secret
JWT_ISSUER=bartap-security-service

#Database properties and variables
JDBC_DATABASE_URL=jdbc:h2:mem:test;MODE=PostgreSQL;DB_CLOSE_DELAY=-1
DRIVER_CLASS_NAME=org.h2.Driver
#Gateway url
GATEWAY_URL=http://localhost:8081${server.servlet.context-path}
9 changes: 6 additions & 3 deletions core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Standard configurations
spring.application.name=bartap-core
spring.application.name=core
spring.profiles.active=dev
server.port=8082
server.servlet.context-path=/api
Expand All @@ -15,7 +15,10 @@ spring.datasource.driverClassName=${DRIVER_CLASS_NAME}
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}

# Kafka
spring.kafka.bootstrap-servers=${BOOTSTRAP_SERVERS:localhost:9092}
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.auto-offset-reset=earliest
# Eureka Registry
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
14 changes: 14 additions & 0 deletions eureka-server/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id 'java'
id 'application'
}

//project.mainClassName = 'com.tungstun.eurekaserver.EurekaServerApplication'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:3.1.3'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tungstun.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {


public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}

}
5 changes: 5 additions & 0 deletions eureka-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spring.application.name=eureka-server
server.port=8761
# Eureka
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.tungstun.eurekaserver;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class EurekaServerApplicationTests {

@Test
void contextLoads() {
}

}
Loading