Skip to content

Commit

Permalink
Finish 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lex-em committed Feb 19, 2019
2 parents daee845 + fb0861a commit fb519a9
Show file tree
Hide file tree
Showing 23 changed files with 400 additions and 220 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
language: java
install: true
script: gradle build --continue
jdk:
- oraclejdk8
script: ./gradlew build --continue
before_install:
- chmod u+x gradlew
before_deploy:
- gradle generatePomFileForMavenPublication
- ./gradlew generatePomFileForMavenPublication
deploy:
key:
secure: Koqvbo26cGgG5QHR9zSGojtvkVtRMxkd3rTejEyWHXnmjbDAnWVLeJf81pz6Vn2lrHbZkCHx+Ec4t3Cptq+v5fXlrgKtjYUORirMK4KWKT0ZLwE41oFo37Y8YVtRLlUiIk7BIteUbY6+p9HTlcQE60TCo9DugVX6Kn8c5tvBtukjckq3uL2/K+IIhtVbHCL6IEMKlQ0O0Wzvhe2m2qTIhAyCjnHgrTM9TxWYqxU5K0ShpL/OgySzXPcJPxy49jPDjp1FmtiMU/Lu5L7l1pzJ8vfWay7rfwJuu0VOy4cCno+8NFNEz5To08eDSIMsHovyqD7CnWkOOeEp9Vkd+D/Td1m2+7xX4UO1HqPmoTaSi2JrBo6FLDdfW+MWd5QGFsSP66hRSaEVV6AicgC1qreFqQQJKxl7XeLlXBt/HCN3qMhh0mKWggN76gnVV9yQY3n1QmtxLR3xgn8DC4xcAepYiDyUsxibVk1k5q1YHmGTpn2AfkrxhB5Dw97f/T8FrG2iO32NopieiugKh7Ln60TEsgDzsscyVic9OGEhQpCHVBI34jSO+/alh8ui+ULcNpreltJNk+tQAGejvMqDTEcYpAXKcuij2CzlFGchnBXnVnJquXP9i/s0s8k/VxARlrY8zUy2AM2lOq0LjNCEPm1whstv2lM2WmUi8mUwdzCFngI=
Expand Down
45 changes: 34 additions & 11 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Swagger addon for Spring Cloud ZUUL
[![Build Status](https://travis-ci.org/lex-em/zuul-springfox-swagger.svg?branch=develop)](https://travis-ci.org/lex-em/zuul-springfox-swagger)
[![Build Status](https://travis-ci.org/lex-em/zuul-springfox-swagger.svg?branch=develop)](https://travis-ci.org/lex-em/zuul-springfox-swagger)[![Release](https://jitpack.io/v/ru.reliabletech/zuul-springfox-swagger.svg)](https://jitpack.io/#ru.reliabletech/zuul-springfox-swagger)

## Overview

Expand All @@ -14,6 +14,7 @@ Repository contains library for using springfox swagger UI under ZUUL proxy
Swagger addon for Spring Cloud ZUUL is open source software released under the [Apache 2.0 license][1].

## Usage
### Configuration
Plugin extends ZUUL configuration:
```yaml
zuul:
Expand All @@ -31,32 +32,54 @@ zuul:
swaggerUrl: api-documentation
protocol: https://
```
To turn plugin on just put annotation `@EnableZuulSpringfoxSwagger`:
```java
@Configuration
@EnableZuulSpringfoxSwagger
public class YourConfiguration {
...
}
```

For use it you should include dependency (** SNAPSHOTS DO NOT AVAILABLE AT THIS MOMENT [#1](/../../issues/1)**):
Also plugin needs Swagger2 and RestTemplate (load balanced is preferable) to be configured.

If the project configuration do not contain that, then it will be configured automatically (since version 0.1.1).

Since 0.2.0 version plugin supports versioned api (and other with route transformations via ServiceRouteMapper).
Any `org.springframework.cloud.netflix.zuul.filters.discovery.ServiceRouteMapper` bean will turn on this approach, but here some nuances, described in #3.
### Dependency
```groovy
repositories {
...
jcenter()
// or
maven { url 'https://jitpack.io' }
}
dependencies {
...
compile "ru.reliabletech:zuul-springfox-swagger:${zuulSpringfoxSwaggerVersion}"
...
}
...
```
And add annotation:
```java
@Configuration
@EnableZuulSpringfoxSwagger
public class YourConfiguration {
Also available snapshots in jitpack version notation develop-SNAPSHOT:
```groovy
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
...
compile "ru.reliabletech:zuul-springfox-swagger:develop-SNAPSHOT"
...
}
...
```
Also plugin needs Swagger2 and RestTemplate (load balanced is preferable) to be configured.

If the project configuration do not contain that, then it will be configured automatically (since version 0.1.1).

## Build

Gradle tasks may be running via `gradle` wrapper - `gradlew`(gradle v4.3.1) from project root folder.

* build: `gradle clean build`

[1]: http://www.apache.org/licenses/LICENSE-2.0.html
[1]: http://www.apache.org/licenses/LICENSE-2.0.html
72 changes: 35 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,60 +17,58 @@ apply plugin: 'maven-publish'

// project properties
group 'ru.reliabletech'
def artifact = 'zuul-springfox-swagger'
version '0.1.1'
def libName = 'zuul-springfox-swagger'
version '0.2.0'
sourceCompatibility = 1.8
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": new Date()
"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: java.time.LocalDate.now().format(DateTimeFormatter.ISO_DATE))
}

build.dependsOn expandDescriptor

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

dependencyManagement {
imports {
Expand All @@ -82,12 +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'
}
task wrapper(type: Wrapper) {
gradleVersion = '4.3.1'
compileOnly 'org.springframework.boot:spring-boot-configuration-processor:1.5.9.RELEASE'
}
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
2 changes: 2 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
GROUP: "ru.reliabletech"
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import org.springframework.context.annotation.Import;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;

/**
* Enabling ZuulSpringfoxSwaggerPlugin annotation.
*
* @author Alexandr Emelyanov <[email protected]>
* on 27.11.2017.
*/
Expand Down

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
@@ -1,18 +1,28 @@
package ru.reliabletech.zuul.swagger;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.zuul.filters.discovery.ServiceRouteMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import ru.reliabletech.zuul.swagger.props.ServicesSwaggerInfo;
import ru.reliabletech.zuul.swagger.service.GenericRouteService;
import ru.reliabletech.zuul.swagger.service.RouteService;
import ru.reliabletech.zuul.swagger.service.ServiceRouteMapperRouteService;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
* Main configuration for ZuulSpringfoxPlugin
*
* @author Alexandr Emelyanov <[email protected]>
* on 27.11.2017.
*/
@Configuration
@ComponentScan(basePackageClasses = ZuulSpringfoxSwaggerConfiguration.class)
@EnableConfigurationProperties(ServicesSwaggerInfo.class)
public class ZuulSpringfoxSwaggerConfiguration {
Expand All @@ -28,4 +38,25 @@ public RestTemplate restTemplate() {
return new RestTemplate();
}

/**
* Configure automatically {@link ServiceRouteMapper } based {@link RouteService }
*
* @return
*/
@Bean
@ConditionalOnBean(ServiceRouteMapper.class)
public RouteService versionedRouteService() {
return new ServiceRouteMapperRouteService();
}

/**
* Default {@link RouteService}
*
* @return
*/
@Bean
@ConditionalOnMissingBean(RouteService.class)
public RouteService genericRouteService() {
return new GenericRouteService();
}
}
Loading

0 comments on commit fb519a9

Please sign in to comment.