Skip to content

Commit

Permalink
#3 Api versions
Browse files Browse the repository at this point in the history
feature preview. the main work is done
  • Loading branch information
lex-em committed Feb 19, 2019
1 parent 43feec1 commit 8557a74
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 167 deletions.
69 changes: 32 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.time.LocalDate
import java.time.format.DateTimeFormatter

buildscript {
Expand All @@ -16,62 +17,58 @@ apply plugin: 'maven-publish'

// project properties
group 'ru.reliabletech'
def artifact = 'zuul-springfox-swagger'
def libName = 'zuul-springfox-swagger'
version '0.1.2-SNAPSHOT'
sourceCompatibility = 1.8
def currentDate = java.time.LocalDate.now().format(DateTimeFormatter.ISO_DATE)
def currentDate = LocalDate.now().format(DateTimeFormatter.ISO_DATE)

//tasks
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives sourcesJar
}

task expandDescriptor(type: Copy) {
from 'descriptor.json'
into 'build'
expand(version: project.version, date: currentDate)
}

build.dependsOn expandDescriptor
compileJava.dependsOn(processResources)

// plugin settings
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact sourcesJar
groupId project.group
artifactId artifact
artifactId libName
version project.version
}
}
}

model {
tasks.generatePomFileForMavenPublication {
destination = file("$buildDir/libs/$artifact-${version}.pom")
}
}
}

jar {
manifest {
attributes(
"Group": group,
"Artifact-Id": artifact,
"Artifact-Id": libName,
"Version": version,
"Source-Compatibility": sourceCompatibility,
"Build-Time": currentDate
)
}
}

//tasks
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives sourcesJar
}

task expandDescriptor(type: Copy) {
from 'descriptor.json'
into 'build'
expand(version: project.version, date: currentDate)
}

build.dependsOn expandDescriptor
compileJava.dependsOn(processResources)

//dependency management
def springCloudVersion = 'Dalston.SR3'
def springCloudVersion = 'Finchley.SR1'

dependencyManagement {
imports {
Expand All @@ -84,13 +81,11 @@ repositories {
}

dependencies {
compile 'org.springframework.cloud:spring-cloud-starter-eureka'
compile 'org.springframework.cloud:spring-cloud-starter-zuul'
compile 'org.projectlombok:lombok:1.16.18'
compile 'io.springfox:springfox-swagger2:2.7.0'
compileOnly 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
compileOnly 'org.springframework.cloud:spring-cloud-starter-netflix-zuul'
annotationProcessor 'org.projectlombok:lombok:1.18.4'
implementation 'org.projectlombok:lombok:1.18.4'
compile 'io.springfox:springfox-swagger2:2.9.2'
compile 'io.springfox.ui:springfox-swagger-ui-rfc6570:1.0.0'
compileOnly 'org.springframework.boot:spring-boot-configuration-processor:1.5.9.RELEASE'
}
task wrapper(type: Wrapper) {
gradleVersion = '4.3.1'
}
3 changes: 2 additions & 1 deletion descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"gpgSign": false
},
"files":[
{"includePattern": "build/libs/(.*)", "uploadPattern": "ru/reliabletech/zuul-springfox-swagger/${version}/\$1"}
{"includePattern": "build/libs/(.*)", "uploadPattern": "ru/reliabletech/zuul-springfox-swagger/${version}/\$1"},
{"includePattern": "build/publications/maven/pom-default.xml", "uploadPattern": "ru/reliabletech/zuul-springfox-swagger/${version}/pom-${version}.xml"}
],
"publish": true
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-bin.zip

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/ru/reliabletech/zuul/swagger/ServiceInfo.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/ru/reliabletech/zuul/swagger/SwaggerService.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;
import ru.reliabletech.zuul.swagger.props.ServicesSwaggerInfo;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.reliabletech.zuul.swagger.controller;

import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ru.reliabletech.zuul.swagger.service.SwaggerService;

/**
* Controller for api
*
* @author Alexandr Emelyanov <[email protected]>
* on 27.11.2017.
*/
@RestController
public class ZuulSwaggerController {

@Autowired
private SwaggerService swaggerService;

@GetMapping("/api-docs")
public JsonNode getApiDocs(@RequestParam("route") String route) {
return swaggerService.getSwaggerDoc(route);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.reliabletech.zuul.swagger;
package ru.reliabletech.zuul.swagger.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/ru/reliabletech/zuul/swagger/props/ServiceInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.reliabletech.zuul.swagger.props;

import lombok.Data;

/**
* @author Alexandr Emelyanov <[email protected]>
* on 27.11.2017.
*/
@Data
class ServiceInfo {

private String path;

private String serviceId;

private String url;

private String swaggerUri;

private String protocol = "";

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ru.reliabletech.zuul.swagger;
package ru.reliabletech.zuul.swagger.props;

import lombok.Data;
import lombok.*;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
Expand All @@ -17,11 +17,14 @@
public class ServicesSwaggerInfo {

public static final String DEFAULT_SWAGGER_API_URL = "v2/api-docs";
public static final String PROTOCOL_DEFAULT = "http://";

private String prefix;

private String defaultSwaggerUrl = DEFAULT_SWAGGER_API_URL;

private String defaultProtocol = PROTOCOL_DEFAULT;

private Map<String, ServiceInfo> routes = new HashMap<>();

public Set<String> getRouteNames() {
Expand All @@ -30,18 +33,24 @@ public Set<String> getRouteNames() {

public String getSwaggerUrl(String route) {
return Optional.ofNullable(routes.get(route))
.map(ServiceInfo::getSwaggerUrl)
.orElse(defaultSwaggerUrl);
.map(ServiceInfo::getSwaggerUri)
.orElse(defaultSwaggerUrl);
}

public String getDefaultProtocol(String route) {
return Optional.ofNullable(routes.get(route))
.map(ServiceInfo::getProtocol)
.orElse(defaultProtocol);
}

public String getServiceUrl(String route) {
public Optional<String> getServiceUrl(String route) {
return Optional.ofNullable(routes.get(route))
.map(ServiceInfo::getServiceUrl)
.orElse("");
.map(ServiceInfo::getUrl)
.map(url -> String.format("%s%s/", getDefaultProtocol(route), url));
}

public Optional<String> getServicePath(String route) {
return Optional.ofNullable(routes.get(route))
.map(ServiceInfo::getPath);
.map(ServiceInfo::getPath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.reliabletech.zuul.swagger.service;

import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Component;
import ru.reliabletech.zuul.swagger.props.ServicesSwaggerInfo;

/**
* @author Alexandr Emelyanov <[email protected]>
* on 15.02.19.
*/
@ConditionalOnMissingBean(RouteService.class)
@Component
@AllArgsConstructor
public class GenericRouteService implements RouteService {

private ServicesSwaggerInfo servicesSwaggerInfo;

@Override
public String getPath(String route) {
return servicesSwaggerInfo
.getServicePath(route)
.orElse(route);
}
}
Loading

0 comments on commit 8557a74

Please sign in to comment.