Skip to content

Commit

Permalink
Merge pull request wildfly#17905 from pferraro/openapi
Browse files Browse the repository at this point in the history
WFLY-19355 Deploying multiple OpenAPI endpoints can result in a NoSuchElementException
  • Loading branch information
asoldano authored May 22, 2024
2 parents 8ecd490 + f727e3e commit 2580d70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 91 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.stream.Collectors;

import io.smallrye.openapi.api.OpenApiConfig;
import io.smallrye.openapi.api.OpenApiDocument;
import io.smallrye.openapi.runtime.OpenApiProcessor;
import io.smallrye.openapi.runtime.OpenApiStaticFile;
import io.smallrye.openapi.runtime.io.Format;
Expand Down Expand Up @@ -81,12 +82,6 @@ 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 @@ -143,24 +138,32 @@ public OpenAPI get() {
OpenApiConfig config = this.configuration.getOpenApiConfig();
IndexView indexView = new FilteredIndexView(this.index, config);

OpenAPIDocumentBuilder builder = new OpenAPIDocumentBuilder();
builder.config(config);
OpenApiDocument document = OpenApiDocument.newInstance();
document.config(config);
document.modelFromReader(OpenApiProcessor.modelFromReader(config, this.module.getClassLoader(), indexView));

Map.Entry<VirtualFile, Format> entry = this.configuration.getStaticFile();
if (entry != null) {
VirtualFile file = entry.getKey();
Format format = entry.getValue();
try (OpenApiStaticFile staticFile = new OpenApiStaticFile(file.openStream(), format)) {
builder.staticFileModel(OpenApiProcessor.modelFromStaticFile(config, staticFile));
document.modelFromStaticFile(OpenApiProcessor.modelFromStaticFile(config, staticFile));
} catch (IOException e) {
throw MicroProfileOpenAPILogger.LOGGER.failedToLoadStaticFile(e, file.getPathNameRelativeTo(this.root), this.deploymentName);
}
}

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();
// AnnotationScanner implementations are not stateless, so we must create new instances per deployment
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());
}
});
document.modelFromAnnotations(OpenApiProcessor.modelFromAnnotations(config, this.module.getClassLoader(), indexView, Functions.constantSupplier(scanners)));
document.filter(OpenApiProcessor.getFilter(config, this.module.getClassLoader(), indexView));
document.initialize();
OpenAPI model = document.get();

// Generate default title and description based on web metadata
DescriptionGroupMetaData descriptionMetaData = this.metaData.getDescriptionGroup();
Expand Down

0 comments on commit 2580d70

Please sign in to comment.