Skip to content

Commit

Permalink
feat: allow disabling OAS 3.1 resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Jan 6, 2023
1 parent 19f7529 commit 0db5ed9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
import javax.net.ssl.SSLHandshakeException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OpenAPIV3Parser implements SwaggerParserExtension {

public static final String DISABLE_OAS31_RESOLVE = "disableOas31Resolve";
private static final Logger LOGGER = LoggerFactory.getLogger(OpenAPIV3Parser.class);
private static ObjectMapper JSON_MAPPER, YAML_MAPPER;
/**
Expand Down Expand Up @@ -206,28 +209,38 @@ private SwaggerParseResult resolve(SwaggerParseResult result, List<Authorization
if (options != null) {
if (options.isResolve() || options.isResolveFully()) {
if (result.getOpenAPI().getOpenapi() != null && result.getOpenAPI().getOpenapi().startsWith("3.1")) {
DereferencerContext dereferencerContext = new DereferencerContext(
result,
auth,
location,
options,
null,
null,
true
);
List<OpenAPIDereferencer> dereferencers = DereferencersFactory.getInstance().getDereferencers();
if (dereferencers.iterator().hasNext()) {
OpenAPIDereferencer dereferencer = dereferencers.iterator().next();
dereferencer.dereference(dereferencerContext, dereferencers.iterator());
if (StringUtils.isBlank(System.getenv(DISABLE_OAS31_RESOLVE))) {
DereferencerContext dereferencerContext = new DereferencerContext(
result,
auth,
location,
options,
null,
null,
true
);
List<OpenAPIDereferencer> dereferencers = DereferencersFactory.getInstance().getDereferencers();
if (dereferencers.iterator().hasNext()) {
OpenAPIDereferencer dereferencer = dereferencers.iterator().next();
dereferencer.dereference(dereferencerContext, dereferencers.iterator());
}
if (options.isResolveFully()) {
new ResolverFully(options.isResolveCombinators()).resolveFully(result.getOpenAPI());
}
} else {
String msg = "Resolution of OAS 3.1 spec disabled by 'disableOas31Resolve' env variable";
LOGGER.warn(msg);
result.getMessages().add(msg);
}
} else {
OpenAPIResolver resolver = new OpenAPIResolver(result.getOpenAPI(), emptyListIfNull(auth),
location, null, options);
resolver.resolve(result);
if (options.isResolveFully()) {
new ResolverFully(options.isResolveCombinators()).resolveFully(result.getOpenAPI());
}
}
if (options.isResolveFully()) {
new ResolverFully(options.isResolveCombinators()).resolveFully(result.getOpenAPI());
}

}
if (options.isFlatten()) {
final InlineModelResolver inlineModelResolver =
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
<swagger-parser-v2-version>1.0.64</swagger-parser-v2-version>
<commons-io-version>2.11.0</commons-io-version>
<slf4j-version>1.7.30</slf4j-version>
<swagger-core-version>2.2.8-SNAPSHOT</swagger-core-version>
<swagger-core-version>2.2.8</swagger-core-version>
<swagger-core-v2-version>1.6.9</swagger-core-v2-version>
<junit-version>4.13.2</junit-version>
<testng-version>6.14.2</testng-version>
Expand Down

0 comments on commit 0db5ed9

Please sign in to comment.