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

SWG-7517 utilizing updated resolving of swagger-parser-v3 #12137

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.swagger.v3.oas.models.media.BooleanSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.ParseOptions;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.Argument;
import net.sourceforge.argparse4j.inf.ArgumentParser;
Expand All @@ -21,10 +22,7 @@
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand All @@ -46,7 +44,25 @@ public static void main(String[] args) {
LOGGER.error("Could not load resource file.");
return;
}
final OpenAPI openAPI = new OpenAPIV3Parser().readContents(oas3, null, null).getOpenAPI();

ParseOptions parseOptions = null;

if (System.getenv("SAFELY_RESOLVE_URL").equals("true")) {
List<String> allowList = Optional.ofNullable(System.getenv("REMOTE_REF_ALLOW_LIST"))
.map(str -> Arrays.asList(str.split(",")))
.orElseGet(Collections::emptyList);

List<String> blockList = Optional.ofNullable(System.getenv("REMOTE_REF_BLOCK_LIST"))
.map(str -> Arrays.asList(str.split(",")))
.orElseGet(Collections::emptyList);

parseOptions = new ParseOptions();
parseOptions.setSafelyResolveURL(true);
parseOptions.setRemoteRefAllowList(allowList);
parseOptions.setRemoteRefBlockList(blockList);
}

final OpenAPI openAPI = new OpenAPIV3Parser().readContents(oas3, null, parseOptions).getOpenAPI();
final Map<String, Schema> schemaMap = openAPI.getComponents().getSchemas();
final Set<String> schemaNames = schemaMap.keySet();

Expand Down
2 changes: 1 addition & 1 deletion pom.docker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@
<swagger-codegen-generators-version>1.0.40-SNAPSHOT</swagger-codegen-generators-version>
<swagger-core-version>2.2.9</swagger-core-version>
<swagger-core-version-v1>1.6.10</swagger-core-version-v1>
<swagger-parser-version>2.1.13</swagger-parser-version>
<swagger-parser-version>2.1.14-SNAPSHOT</swagger-parser-version>
<swagger-parser-version-v1>1.0.65</swagger-parser-version-v1>
<jackson-version>2.14.2</jackson-version>
<jackson-databind-version>2.14.2</jackson-databind-version>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@
<swagger-codegen-generators-version>1.0.40-SNAPSHOT</swagger-codegen-generators-version>
<swagger-core-version>2.2.9</swagger-core-version>
<swagger-core-version-v1>1.6.10</swagger-core-version-v1>
<swagger-parser-version>2.1.13</swagger-parser-version>
<swagger-parser-version>2.1.14-SNAPSHOT</swagger-parser-version>
<swagger-parser-version-v1>1.0.65</swagger-parser-version-v1>
<jackson-version>2.14.2</jackson-version>
<jackson-databind-version>2.14.2</jackson-databind-version>
Expand Down