Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dependabot/maven/io…
Browse files Browse the repository at this point in the history
….swagger-swagger-compat-spec-parser-1.0.55
  • Loading branch information
lars-sh committed Aug 9, 2021
2 parents 6eed5ae + 5ca7a62 commit 2470ac7
Show file tree
Hide file tree
Showing 29 changed files with 1,343 additions and 766 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: maven
directory: /
schedule:
interval: daily
102 changes: 102 additions & 0 deletions .github/workflows/push-and-pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Build on Push and Pull Request
on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Supported versions as of https://en.wikipedia.org/wiki/Java_version_history
java-version:
- 8
- 11
- 16

name: Build with JDK ${{ matrix.java-version }}
steps:
- name: Cache Dependencies
uses: actions/[email protected]
with:
key: maven-dependencies
path: ~/.m2/repository
- name: Check out
uses: actions/[email protected]
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: ${{ matrix.java-version }}
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE
- name: Clean, Build, Install
run: |
set -o errexit -o pipefail
mvn clean install --activate-profiles dirty,dirty-package --update-snapshots --batch-mode --show-version 2>&1 | tee mvnout.txt
set +o errexit +o pipefail
- id: version
name: Evaluate Version
run: |
project_version=`mvn help:evaluate --quiet --define expression=project.version --define forceStdout`
echo "Version: ${project_version}"
snapshot_version=`echo "${project_version}" | grep --perl-regexp --regexp="-SNAPSHOT$"`
if [ -n "${snapshot_version}" ]; then
echo "Identified as snapshot version"
echo "::set-output name=is-snapshot::true"
else
echo "Identified as release version"
echo "::set-output name=is-snapshot::false"
fi
- name: Test, Verify, Deploy
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.java-version == 8 && steps.version.outputs.is-snapshot == 'true' }}
run: |
set -o errexit -o pipefail
mvn deploy site --batch-mode --show-version 2>&1 | tee --append mvnout.txt
set +o errexit +o pipefail
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Test, Verify
if: ${{ github.event_name != 'push' || github.ref != 'refs/heads/master' || matrix.java-version != 8 || steps.version.outputs.is-snapshot != 'true' }}
run: |
set -o errexit -o pipefail
mvn verify site --define gpg.skip=true --batch-mode --show-version 2>&1 | tee --append mvnout.txt
set +o errexit +o pipefail
- name: Check Output
shell: bash {0}
run: |
chmod +x ./target/mvn-suppressions-parent.sh
mvnout=`cat mvnout.txt | grep --perl-regexp "(?i)\\[(ERR|WARN)" | ./target/mvn-suppressions-parent.sh "$JDK_VERSION"`
if [ -n "${mvnout}" ]; then
echo "[ERROR] The Maven output contains the following unknown warnings and errors:" >&2
echo "${mvnout}" >&2
false
else
echo "[INFO] No unknown warnings and errors found."
echo "${mvnout}" >&2
fi
env:
JDK_VERSION: ${{ matrix.java-version }}
- name: Prepare Site
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.java-version == 8 && steps.version.outputs.is-snapshot == 'true' }}
run: |
if [ -f ./target/site/index.html ]; then
rm ./target/site/index.html
fi
if [ -f ./CHANGELOG.md ]; then
cp ./CHANGELOG.md ./target/site/CHANGELOG.md
fi
if [ -f ./README.md ]; then
cp ./README.md ./target/site/README.md
fi
- name: Deploy Site
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.java-version == 8 && steps.version.outputs.is-snapshot == 'true' }}
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/site
enable_jekyll: true
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

File renamed without changes.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ Download the fatJar or view the changelog on the **[Release Page](https://github
<dependency>
<groupId>com.deepoove</groupId>
<artifactId>swagger-diff</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
```

## Gradle
```shell
compile group: 'com.deepoove', name: 'swagger-diff', version: '1.2.1'
compile group: 'com.deepoove', name: 'swagger-diff', version: '1.2.2'
```

## Usage
Expand All @@ -81,11 +81,9 @@ String html = new HtmlRender("Changelog",
.render(diff);

try {
FileWriter fw = new FileWriter(
"testNewApi.html");
FileWriter fw = new FileWriter("testNewApi.html");
fw.write(html);
fw.close();

} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -96,11 +94,9 @@ try {
```java
String render = new MarkdownRender().render(diff);
try {
FileWriter fw = new FileWriter(
"testDiff.md");
FileWriter fw = new FileWriter("testDiff.md");
fw.write(render);
fw.close();

} catch (IOException e) {
e.printStackTrace();
}
Expand Down
7 changes: 7 additions & 0 deletions mvn-suppressions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function suppressSiteWarnings() {
cat < /dev/stdin \
| grep --invert-match --perl-regexp "^\\[WARNING\\] Unable to find a URL to the parent project\\. The parent menu will NOT be added\\.$"
}

cat < /dev/stdin \
| suppressSiteWarnings
77 changes: 51 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
<parent>
<groupId>de.lars-sh</groupId>
<artifactId>parent</artifactId>
<version>0.9.7</version>
<relativePath></relativePath>
<version>0.9.12</version>
<relativePath />
</parent>

<groupId>com.hlag.api</groupId>
<artifactId>swagger-diff</artifactId>
<version>1.2.2-SNAPSHOT</version>
<packaging>jar</packaging>
<version>1.2.3-SNAPSHOT</version>

<name>swagger-diff</name>
<description>diff swagger api document</description>
<url>http://maven.apache.org</url>
<url>https://${parent-pom.github.organization}.github.io/${parent-pom.github.project}/</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
Expand All @@ -31,32 +30,19 @@
</developer>
</developers>

<scm>
<connection>scm:git:[email protected]:Sayi/swagger-diff.git</connection>
<developerConnection>scm:git:[email protected]:Sayi/swagger-diff.git</developerConnection>
<url>[email protected]:Sayi/swagger-diff.git</url>
</scm>
<distributionManagement>
<snapshotRepository>
<id>oss</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>oss</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<properties>
<parent-pom.create-changelog-md>false</parent-pom.create-changelog-md>
<parent-pom.default-sources-folder>java</parent-pom.default-sources-folder>
<parent-pom.create-lombok-config>false</parent-pom.create-lombok-config>
<parent-pom.default-sources-folder>java</parent-pom.default-sources-folder>
<parent-pom.github.organization>Hapag-Lloyd</parent-pom.github.organization>
<parent-pom.github.project>swagger-diff</parent-pom.github.project>

<eclipse.compiler.javadoc>disabled</eclipse.compiler.javadoc>
<eclipse.compiler.nullAnalysis>disabled</eclipse.compiler.nullAnalysis>
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>

<checkstyle.skip>true</checkstyle.skip>
<formatter.skip>true</formatter.skip>
<gpg.skip>true</gpg.skip>
<pmd.skip>true</pmd.skip>
<spotbugs.skip>true</spotbugs.skip>
</properties>
Expand All @@ -65,7 +51,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.31</version>
<version>1.2.78</version>
</dependency>
<dependency>
<groupId>com.beust</groupId>
Expand All @@ -75,7 +61,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
<version>2.12.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>com.j2html</groupId>
Expand Down Expand Up @@ -111,8 +102,42 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<usedDependencies>
<usedDependency>org.junit.vintage:junit-vintage-engine</usedDependency>
</usedDependencies>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<!-- JDK 15 and 16, Maven Javadoc Plugin: Logs warnings on missing JavaDoc comments inside generated code -->
<profile>
<id>fix-jdk15-and-16</id>
<activation>
<jdk>[15,17)</jdk>
</activation>
<properties>
<doclint>all,-missing</doclint>
</properties>
</profile>
</profiles>
</project>
54 changes: 36 additions & 18 deletions src/main/java/com/deepoove/swagger/diff/SwaggerDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class SwaggerDiff {
* old api-doc location:Json or Http
* @param newSpec
* new api-doc location:Json or Http
* @return swagger differences
*/
public static SwaggerDiff compareV1(String oldSpec, String newSpec) {
return compare(oldSpec, newSpec, null, null);
Expand All @@ -48,23 +49,52 @@ public static SwaggerDiff compareV1(String oldSpec, String newSpec) {
* old api-doc location:Json or Http
* @param newSpec
* new api-doc location:Json or Http
* @return swagger differences
*/
public static SwaggerDiff compareV2(String oldSpec, String newSpec) {
return compare(oldSpec, newSpec, null, SWAGGER_VERSION_V2);
}


public static SwaggerDiff compare(String oldSpec, String newSpec,
List<AuthorizationValue> auths, String version) {
return new SwaggerDiff(oldSpec, newSpec, auths, version).compare();
/**
* compare two swagger v2.0 Sring
*
* @param oldSpec old api-doc json as string
* @param newSpec new api-doc json as string
* @return swagger differences
*/
public static SwaggerDiff compareV2Raw(String oldSpec, String newSpec) {
return new SwaggerDiff(oldSpec, newSpec).compare();
}

/**
* Compare two swagger v2.0 docs by JsonNode
*
* @param oldSpec
* old Swagger specification document in v2.0 format as a JsonNode
* @param newSpec
* @param auths
* @param version
* new Swagger specification document in v2.0 format as a JsonNode
* @return swagger differences
*/
public static SwaggerDiff compareV2(JsonNode oldSpec, JsonNode newSpec) {
return new SwaggerDiff(oldSpec, newSpec).compare();
}

public static SwaggerDiff compare(String oldSpec, String newSpec,
List<AuthorizationValue> auths, String version) {
return new SwaggerDiff(oldSpec, newSpec, auths, version).compare();
}

private SwaggerDiff(String rawOldSpec, String rawNewSpec) {
SwaggerParser swaggerParser = new SwaggerParser();
oldSpecSwagger = swaggerParser.parse(rawOldSpec);
newSpecSwagger = swaggerParser.parse(rawNewSpec);

if (null == oldSpecSwagger || null == newSpecSwagger) {
throw new RuntimeException("cannot read api-doc from spec.");
}
}

private SwaggerDiff(String oldSpec, String newSpec, List<AuthorizationValue> auths,
String version) {
if (SWAGGER_VERSION_V2.equals(version)) {
Expand All @@ -84,18 +114,6 @@ private SwaggerDiff(String oldSpec, String newSpec, List<AuthorizationValue> aut
if (null == oldSpecSwagger || null == newSpecSwagger) { throw new RuntimeException(
"cannot read api-doc from spec."); }
}

/**
* Compare two swagger v2.0 docs by JsonNode
*
* @param oldSpec
* old Swagger specification document in v2.0 format as a JsonNode
* @param newSpec
* new Swagger specification document in v2.0 format as a JsonNode
*/
public static SwaggerDiff compareV2(JsonNode oldSpec, JsonNode newSpec) {
return new SwaggerDiff(oldSpec, newSpec).compare();
}

private SwaggerDiff(JsonNode oldSpec, JsonNode newSpec) {
SwaggerParser swaggerParser = new SwaggerParser();
Expand Down
Loading

0 comments on commit 2470ac7

Please sign in to comment.