Skip to content

Commit

Permalink
Merge pull request wildfly#17249 from pferraro/openapi
Browse files Browse the repository at this point in the history
WFLY-18599 Upgrade smallrye-open-api to 3.6.2
  • Loading branch information
bstansberry authored Oct 5, 2023
2 parents 4ee874c + cfb3e15 commit e28de86
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<dependencies>
<module name="jakarta.ws.rs.api"/>

<module name="io.smallrye.jandex"/>
<module name="io.smallrye.openapi"/>

<module name="io.undertow.core"/>
Expand All @@ -36,7 +37,6 @@
<module name="org.jboss.as.network"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.web-common"/>
<module name="io.smallrye.jandex"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.metadata.common"/>
<module name="org.jboss.metadata.web"/>
Expand All @@ -48,6 +48,8 @@
<module name="org.jboss.vfs"/>

<module name="org.wildfly.clustering.service"/>
<module name="org.wildfly.common"/>
<module name="org.wildfly.extension.undertow"/>
<module name="org.wildfly.security.elytron-private"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.wildfly.extension.undertow.UndertowExtension;

import io.smallrye.openapi.api.OpenApiConfig;
import io.smallrye.openapi.api.OpenApiConfigImpl;
import io.smallrye.openapi.runtime.io.Format;

/**
Expand Down Expand Up @@ -130,7 +129,7 @@ private static Map.Entry<VirtualFile, Format> findStaticFile(VirtualFile root) {

DeploymentOpenAPIConfiguration(DeploymentUnit unit) {
this.config = ConfigProvider.getConfig(unit.getAttachment(Attachments.MODULE).getClassLoader());
this.openApiConfig = OpenApiConfigImpl.fromConfig(this.config);
this.openApiConfig = OpenApiConfig.fromConfig(this.config);
this.staticFile = findStaticFile(unit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot());
// Fetch server/host as determined by Undertow DUP
ModelNode model = unit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT).getDeploymentSubsystemModel(UndertowExtension.SUBSYSTEM_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
Expand Down Expand Up @@ -61,12 +61,14 @@
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SimpleServiceNameProvider;
import org.wildfly.clustering.service.SupplierDependency;
import org.wildfly.common.function.Functions;
import org.wildfly.extension.microprofile.openapi.logging.MicroProfileOpenAPILogger;
import org.wildfly.extension.undertow.Capabilities;
import org.wildfly.extension.undertow.Host;
import org.wildfly.extension.undertow.UndertowListener;
import org.wildfly.extension.undertow.UndertowService;
import org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService;
import org.wildfly.security.manager.WildFlySecurityManager;

/**
* Configures a service that provides an OpenAPI model for a deployment.
Expand All @@ -79,6 +81,12 @@ public class OpenAPIModelServiceConfigurator extends SimpleServiceNameProvider i
private static final String RELATIVE_SERVER_URLS = "mp.openapi.extensions.servers.relative";
private static final String DEFAULT_TITLE = "Generated API";
private static final Set<String> REQUISITE_LISTENERS = Collections.singleton("http");
private static final Iterable<AnnotationScanner> SCANNERS = WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() {
@Override
public Iterable<AnnotationScanner> run() {
return ServiceLoader.load(AnnotationScanner.class, AnnotationScanner.class.getClassLoader()).stream().map(ServiceLoader.Provider::get).collect(Collectors.toList());
}
});

static {
// Set the static OASFactoryResolver eagerly avoiding the need perform TCCL service loading later
Expand Down Expand Up @@ -149,11 +157,9 @@ public OpenAPI get() {
}
}

// Workaround for https://github.com/smallrye/smallrye-open-api/issues/1508
ClassLoader scannerClassLoader = new CompositeClassLoader(List.of(AnnotationScanner.class.getClassLoader(), this.module.getClassLoader()));
builder.annotationsModel(OpenApiProcessor.modelFromAnnotations(config, scannerClassLoader, indexView));
builder.readerModel(OpenApiProcessor.modelFromReader(config, this.module.getClassLoader()));
builder.filter(OpenApiProcessor.getFilter(config, this.module.getClassLoader()));
builder.annotationsModel(OpenApiProcessor.modelFromAnnotations(config, this.module.getClassLoader(), indexView, Functions.constantSupplier(SCANNERS)));
builder.readerModel(OpenApiProcessor.modelFromReader(config, this.module.getClassLoader(), indexView));
builder.filter(OpenApiProcessor.getFilter(config, this.module.getClassLoader(), indexView));
OpenAPI model = builder.build();

// Generate default title and description based on web metadata
Expand Down Expand Up @@ -234,44 +240,4 @@ private static Server createServer(String protocol, String host, int port, Strin
return null;
}
}

private static class CompositeClassLoader extends ClassLoader {
private final List<ClassLoader> loaders;

CompositeClassLoader(List<ClassLoader> loaders) {
this.loaders = loaders;
}

@Override
public Enumeration<URL> getResources(String name) throws IOException {
List<URL> result = new LinkedList<>();
for (ClassLoader loader : this.loaders) {
result.addAll(Collections.list(loader.getResources(name)));
}
return Collections.enumeration(result);
}

@Override
protected URL findResource(String name) {
for (ClassLoader loader : this.loaders) {
URL url = loader.getResource(name);
if (url != null) {
return url;
}
}
return super.findResource(name);
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
for (ClassLoader loader : this.loaders) {
try {
return loader.loadClass(name);
} catch (ClassNotFoundException e) {
// try again
}
}
return super.findClass(name);
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
<version.io.perfmark>0.23.0</version.io.perfmark>
<version.io.reactivex.rxjava2>2.2.21</version.io.reactivex.rxjava2>
<version.io.reactivex.rxjava3>3.1.6</version.io.reactivex.rxjava3>
<version.io.smallrye.open-api>3.5.1</version.io.smallrye.open-api>
<version.io.smallrye.open-api>3.6.2</version.io.smallrye.open-api>
<version.io.smallrye.reactive-utils>2.6.0</version.io.smallrye.reactive-utils>
<version.io.smallrye.smallrye-common>2.1.2</version.io.smallrye.smallrye-common>
<version.io.smallrye.smallrye-config>3.3.4</version.io.smallrye.smallrye-config>
Expand Down

0 comments on commit e28de86

Please sign in to comment.