Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/maven-pulls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11, 14 ]
java: [ 11, 14, 17 ]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11, 14 ]
java: [ 11, 14, 17 ]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
mvn --no-transfer-progress -B install --file pom.xml
export MY_JAVA_VERSION=`java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1`
echo "JAVA VERSION" ${MY_JAVA_VERSION}
if [[ ${MY_JAVA_VERSION} == "8" ]];
if [[ ${MY_JAVA_VERSION} == "11" ]];
then
export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
echo "POM VERSION" ${MY_POM_VERSION}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/next-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 2.7
- name: Set up Java 8
- name: Set up Java 11
uses: actions/setup-java@v2
with:
java-version: 8
java-version: 11
distribution: 'zulu'
server-id: ossrh
server-username: MAVEN_USERNAME
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 2.7
- name: Set up Java 8
- name: Set up Java 11
uses: actions/setup-java@v2
with:
java-version: 8
java-version: 11
distribution: 'zulu'
server-id: ossrh
server-username: MAVEN_USERNAME
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 2.7
- name: Set up Java 8
- name: Set up Java 11
uses: actions/setup-java@v2
with:
java-version: 8
java-version: 11
distribution: 'zulu'
server-id: ossrh
server-username: MAVEN_USERNAME
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**NOTE:** Since version 2.1.0 Swagger Parser supports OpenAPI 3.1; see [this page](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---OpenAPI-3.1) for details

![Build Master - Java 8, 11, and 14](https://github.com/swagger-api/swagger-parser/workflows/Build%20Test%20Deploy%20master/badge.svg?branch=master)
![Build Master - Java 11, 14 and 17](https://github.com/swagger-api/swagger-parser/workflows/Build%20Test%20Deploy%20master/badge.svg?branch=master)

# Table of contents

Expand Down Expand Up @@ -121,7 +121,7 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
#### Prerequisites
You need the following installed and available in your $PATH:

* [Java 1.8](http://java.oracle.com)
* Java 11
* [Apache maven 3.x](http://maven.apache.org/)

After cloning the project, you can build it from source with this command:
Expand Down
45 changes: 36 additions & 9 deletions modules/swagger-parser-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-version}</version>
<configuration>
<testNGArtifactName>none:none</testNGArtifactName>
<argLine>-javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit-version}/jmockit-${jmockit-version}.jar --add-opens java.base/java.lang=ALL-UNNAMED -Djdk.attach.allowAttachSelf</argLine>
</configuration>
<executions>
<execution>
<id>test-testng</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<junitArtifactName>none:none</junitArtifactName>
<testNGArtifactName>org.testng:testng</testNGArtifactName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -40,7 +62,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<version>3.3.0</version>
<executions>
<execution>
<id>process-resources</id>
Expand Down Expand Up @@ -73,8 +95,10 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
Expand All @@ -84,13 +108,16 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.0</version>
<version>${slf4j-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng-version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

</project>
</project>
35 changes: 33 additions & 2 deletions modules/swagger-parser-v2-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,32 @@
<artifactId>swagger-parser-v2-converter</artifactId>
<packaging>jar</packaging>
<name>swagger-parser-v2-converter</name>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-version}</version>
<configuration>
<testNGArtifactName>none:none</testNGArtifactName>
<argLine>-javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit-version}/jmockit-${jmockit-version}.jar --add-opens java.base/java.lang=ALL-UNNAMED -Djdk.attach.allowAttachSelf</argLine>
</configuration>
<executions>
<execution>
<id>test-testng</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<junitArtifactName>none:none</junitArtifactName>
<testNGArtifactName>org.testng:testng</testNGArtifactName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
Expand Down Expand Up @@ -75,7 +100,13 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<version>${testng-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.swagger.parser.test;

import io.swagger.util.Yaml;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
Expand Down
9 changes: 4 additions & 5 deletions modules/swagger-parser-v3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<artifactId>swagger-parser-v3</artifactId>
<packaging>jar</packaging>
<name>swagger-parser-v3</name>
<build>
</build>
<dependencies>
<dependency>
<groupId>io.swagger.core.v3</groupId>
Expand Down Expand Up @@ -61,7 +59,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<version>${testng-version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -73,10 +71,9 @@
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>1.57</version>
<version>${wiremock-version}</version>
<scope>test</scope>

<classifier>standalone</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand All @@ -87,6 +84,8 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,34 @@ public static boolean isJson(String contents) {
return contents.toString().trim().startsWith("{");
}

public static LoaderOptions buildLoaderOptions() {
LoaderOptions loaderOptions = new LoaderOptions();
try {
Method method = LoaderOptions.class.getMethod("setMaxAliasesForCollections", int.class);
method.invoke(loaderOptions, options.getMaxYamlAliasesForCollections());
method = LoaderOptions.class.getMethod("setAllowRecursiveKeys", boolean.class);
method.invoke(loaderOptions, options.isYamlAllowRecursiveKeys());
} catch (ReflectiveOperationException e) {
LOGGER.debug("using snakeyaml < 1.25, not setting YAML Billion Laughs Attack snakeyaml level protection");
}
return loaderOptions;
}

public static JsonNode readYamlTree(String contents) {
return readYamlTree(contents, null, new SwaggerParseResult());
}
public static JsonNode readYamlTree(String contents, ParseOptions parseOptions, SwaggerParseResult deserializationUtilsResult) {

if (parseOptions != null && parseOptions.isLegacyYamlDeserialization()) {
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor(buildLoaderOptions()));
return Json.mapper().convertValue(yaml.load(contents), JsonNode.class);
}
try {
org.yaml.snakeyaml.Yaml yaml = null;
if (options.isValidateYamlInput()) {
yaml = buildSnakeYaml(new CustomSnakeYamlConstructor());
} else {
yaml = buildSnakeYaml(new SafeConstructor());
yaml = buildSnakeYaml(new SafeConstructor(buildLoaderOptions()));
}
Object o = yaml.load(contents);
if (options.isValidateYamlInput()) {
Expand Down Expand Up @@ -244,7 +257,7 @@ public static <T> T readYamlValue(String contents, Class<T> expectedType) {
return readYamlValue(contents, expectedType, false);
}
public static <T> T readYamlValue(String contents, Class<T> expectedType, boolean openapi31) {
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor(buildLoaderOptions()));
ObjectMapper jsonMapper = openapi31 ? Json31.mapper() : Json.mapper();
return jsonMapper.convertValue(yaml.load(contents), expectedType);
}
Expand All @@ -256,20 +269,12 @@ public static org.yaml.snakeyaml.Yaml buildSnakeYaml(BaseConstructor constructor
return new org.yaml.snakeyaml.Yaml(constructor);
}
try {
LoaderOptions loaderOptions = new LoaderOptions();
Method method = LoaderOptions.class.getMethod("setMaxAliasesForCollections", int.class);
method.invoke(loaderOptions, options.getMaxYamlAliasesForCollections());
method = LoaderOptions.class.getMethod("setAllowRecursiveKeys", boolean.class);
method.invoke(loaderOptions, options.isYamlAllowRecursiveKeys());
method = LoaderOptions.class.getMethod("setAllowDuplicateKeys", boolean.class);
method.invoke(loaderOptions, false);
method = LoaderOptions.class.getMethod("setCodePointLimit", int.class);
method.invoke(loaderOptions, options.getMaxYamlCodePoints());
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(constructor, new Representer(), new DumperOptions(), loaderOptions, new CustomResolver());
LoaderOptions loaderOptions = buildLoaderOptions();
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(constructor, new Representer(new DumperOptions()), new DumperOptions(), loaderOptions, new CustomResolver());
return yaml;
} catch (ReflectiveOperationException e) {
} catch (Exception e) {
//
LOGGER.debug("using snakeyaml < 1.25, not setting YAML Billion Laughs Attack snakeyaml level protection");
LOGGER.error("error building snakeYaml", e);
}
return new org.yaml.snakeyaml.Yaml(constructor);
}
Expand Down Expand Up @@ -396,6 +401,10 @@ public SnakeException(String message, Throwable cause) {

static class CustomSnakeYamlConstructor extends SafeConstructor {

public CustomSnakeYamlConstructor() {
super(buildLoaderOptions());
}

private boolean checkNode(MappingNode node, Integer depth) {
if (node.getValue() == null) return true;
if (depth > options.getMaxYamlDepth()) return false;
Expand Down
Loading