Skip to content

Commit

Permalink
New Route SPI
Browse files Browse the repository at this point in the history
Unlike the current one, this SPI allows declaring routes without having
to depend on Quarkus Vert.x HTTP. Thus, if an extension declares a route
with this SPI, and Quarkus Vert.x HTTP is not present, the route is ignored.
However, if Quarkus Vert.x HTTP is present, the route is registered.
  • Loading branch information
cescoffier committed Jan 12, 2024
1 parent 20eeab4 commit 50c898b
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import io.quarkus.info.runtime.spi.InfoContributor;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.deployment.spi.RouteBuildItem;

public class InfoProcessor {

Expand Down Expand Up @@ -283,14 +283,12 @@ RouteBuildItem defineRoute(InfoBuildTimeConfig buildTimeConfig,
List<InfoContributor> infoContributors = contributors.stream()
.map(InfoBuildTimeContributorBuildItem::getInfoContributor)
.collect(Collectors.toList());

unremovableBeanBuildItemBuildProducer.produce(UnremovableBeanBuildItem.beanTypes(InfoContributor.class));
return nonApplicationRootPathBuildItem.routeBuilder()
.management()
.route(buildTimeConfig.path())
.routeConfigKey("quarkus.info.path")
.handler(recorder.handler(buildTimeInfo, infoContributors))
.displayOnNotFoundPage()
.blockingRoute()

return RouteBuildItem.newManagementRoute(buildTimeConfig.path())
.withRoutePathConfigKey("quarkus.info.path")
.withRequestHandler(recorder.handler(buildTimeInfo, infoContributors))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
import io.quarkus.vertx.http.deployment.FilterBuildItem;
import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.deployment.SecurityInformationBuildItem;
import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem;
import io.quarkus.vertx.http.deployment.spi.RouteBuildItem;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceConfiguration;
import io.smallrye.openapi.api.OpenApiConfig;
Expand Down Expand Up @@ -305,32 +305,31 @@ void handler(LaunchModeBuildItem launch,
}
}

routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management("quarkus.smallrye-openapi.management.enabled")
.routeFunction(openApiConfig.path, corsFilter)
.routeConfigKey("quarkus.smallrye-openapi.path")
.handler(handler)
routes.produce(RouteBuildItem.newManagementRoute(openApiConfig.path, "quarkus.smallrye-openapi.management.enabled")
.withRouteCustomizer(corsFilter)
.withRoutePathConfigKey("quarkus.smallrye-openapi.path")
.withRequestHandler(handler)
.displayOnNotFoundPage("Open API Schema document")
.blockingRoute()
.asBlockingRoute()
.build());

routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management("quarkus.smallrye-openapi.management.enabled")
.routeFunction(openApiConfig.path + ".json", corsFilter)
.handler(handler)
.build());

routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management("quarkus.smallrye-openapi.management.enabled")
.routeFunction(openApiConfig.path + ".yaml", corsFilter)
.handler(handler)
.build());

routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management("quarkus.smallrye-openapi.management.enabled")
.routeFunction(openApiConfig.path + ".yml", corsFilter)
.handler(handler)
.build());
routes.produce(
RouteBuildItem.newManagementRoute(openApiConfig.path + ".json", "quarkus.smallrye-openapi.management.enabled")
.withRouteCustomizer(corsFilter)
.withRequestHandler(handler)
.build());

routes.produce(
RouteBuildItem.newManagementRoute(openApiConfig.path + ".yaml", "quarkus.smallrye-openapi.management.enabled")
.withRouteCustomizer(corsFilter)
.withRequestHandler(handler)
.build());

routes.produce(
RouteBuildItem.newManagementRoute(openApiConfig.path + ".yml", "quarkus.smallrye-openapi.management.enabled")
.withRouteCustomizer(corsFilter)
.withRequestHandler(handler)
.build());

// If management is enabled and swagger-ui is part of management, we need to add CORS so that swagger can hit the endpoint
if (isManagement(managementInterfaceBuildTimeConfig, openApiConfig, launch)) {
Expand Down
5 changes: 5 additions & 0 deletions extensions/vertx-http/deployment-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
</dependency>
</dependencies>

</project>

0 comments on commit 50c898b

Please sign in to comment.