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
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,36 @@ public SwaggerParseResult readContents(String swaggerAsString, List<Authorizatio
return result;
}

/**
* Locates extensions on the current thread class loader and then, if it differs
* from this class classloader (as in OSGi), locates extensions from this
* class classloader as well.
*
* @return a list of extensions
*/
protected List<SwaggerParserExtension> getExtensions() {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
List<SwaggerParserExtension> extensions = getExtensions(tccl);
ClassLoader cl = SwaggerParserExtension.class.getClassLoader();
if (cl != tccl) {
extensions.addAll(getExtensions(cl));
}
extensions.add(0, new OpenAPIV3Parser());
return extensions;
}

protected List<SwaggerParserExtension> getExtensions(ClassLoader cl) {
List<SwaggerParserExtension> extensions = new ArrayList<>();

ServiceLoader<SwaggerParserExtension> loader = ServiceLoader.load(SwaggerParserExtension.class);
ServiceLoader<SwaggerParserExtension> loader = ServiceLoader.load(SwaggerParserExtension.class, cl);
Iterator<SwaggerParserExtension> itr = loader.iterator();
while (itr.hasNext()) {
extensions.add(itr.next());
}
extensions.add(0, new OpenAPIV3Parser());
return extensions;
}

/**
/**
* Transform the swagger-model version of AuthorizationValue into a parser-specific one, to avoid
* dependencies across extensions
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,23 @@ public void shouldParseExternalSchemaModelHavingReferenceToItsLocalModel() {
assertThat(((Schema) modelSchema.getProperties().get("id")).get$ref(), equalTo("#/components/schemas/ValueId"));
}


@Test(description = "Test that extensions can be found on the class classloader in addition to tccl.")
public void testIssue1003_ExtensionsClassloader() {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
OpenAPI api = null;
try {
// Temporarily switch tccl to an unproductive cl
final ClassLoader tcclTemp = new java.net.URLClassLoader(new java.net.URL[] {},
ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(tcclTemp);
api = new OpenAPIV3Parser().read("src/test/resources/test.yaml");
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
assertNotNull(api);
}

@Test
public void shouldParseApiWithMultipleParameterReferences() {
// given
Expand All @@ -1821,6 +1838,7 @@ public void shouldParseApiWithMultipleParameterReferences() {
assertThat(parameters.get("NameParam").getName(), equalTo("name"));

assertThat(result.getMessages(), equalTo(emptyList()));

}

private static int getDynamicPort() {
Expand Down