io.quarkus.smallrye.openapi.runtime.OpenApiRecorder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-smallrye-openapi Show documentation
Show all versions of quarkus-smallrye-openapi Show documentation
Document your REST APIs with OpenAPI - comes with Swagger UI
The newest version!
package io.quarkus.smallrye.openapi.runtime;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.eclipse.microprofile.openapi.OASFilter;
import org.jboss.logging.Logger;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.vertx.http.runtime.HttpConfiguration;
import io.quarkus.vertx.http.runtime.filters.Filter;
import io.vertx.core.Handler;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;
@Recorder
public class OpenApiRecorder {
private static final Logger log = Logger.getLogger(OpenApiRecorder.class);
final RuntimeValue configuration;
public OpenApiRecorder(RuntimeValue configuration) {
this.configuration = configuration;
}
public Consumer corsFilter(Filter filter) {
if (configuration.getValue().corsEnabled && filter.getHandler() != null) {
return new Consumer() {
@Override
public void accept(Route route) {
route.order(-1 * filter.getPriority()).handler(filter.getHandler());
}
};
}
return null;
}
public Handler handler(OpenApiRuntimeConfig runtimeConfig) {
if (runtimeConfig.enable) {
return new OpenApiHandler();
} else {
return new OpenApiNotFoundHandler();
}
}
public void setupClDevMode(ShutdownContext shutdownContext) {
OpenApiConstants.classLoader = Thread.currentThread().getContextClassLoader();
shutdownContext.addShutdownTask(new Runnable() {
@Override
public void run() {
OpenApiConstants.classLoader = null;
}
});
}
public Supplier autoSecurityFilterSupplier(OASFilter autoSecurityFilter) {
return new Supplier<>() {
@Override
public OASFilter get() {
return autoSecurityFilter;
}
};
}
public Supplier> createUserDefinedRuntimeFilters(List filters) {
return new Supplier