This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new 560b0d21a4 Automatically register Camel REST API context path with the 
Quarkus Swagger UI
560b0d21a4 is described below

commit 560b0d21a4ccc000546618cb91db0c42e83d79da
Author: James Netherton <[email protected]>
AuthorDate: Mon Jan 19 07:37:40 2026 +0000

    Automatically register Camel REST API context path with the Quarkus Swagger 
UI
    
    Fixes #8066
---
 .../pages/reference/extensions/openapi-java.adoc   | 29 +++++++++---
 extensions/openapi-java/deployment/pom.xml         |  4 ++
 .../java/deployment/OpenApiJavaProcessor.java      | 11 +++++
 .../java/deployment/SwaggerCamelUrlTest.java       | 53 ++++++++++++++++++++++
 extensions/openapi-java/runtime/pom.xml            |  4 ++
 .../openapi-java/runtime/src/main/doc/usage.adoc   | 27 ++++++++---
 6 files changed, 114 insertions(+), 14 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/openapi-java.adoc 
b/docs/modules/ROOT/pages/reference/extensions/openapi-java.adoc
index 32df3ea284..6e7e07b3f9 100644
--- a/docs/modules/ROOT/pages/reference/extensions/openapi-java.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/openapi-java.adoc
@@ -47,23 +47,38 @@ endif::[]
 
 [id="extensions-openapi-java-usage"]
 == Usage
-You can use this extension to expose REST DSL services to Quarkus OpenAPI. With
-`quarkus-smallrye-openapi`, you can access them by `/q/openapi?format=json`.
+[id="extensions-openapi-java-usage-swagger-ui-for-development"]
+=== Swagger UI for development
 
-Refer to the https://quarkus.io/guides/openapi-swaggerui[Quarkus OpenAPI 
guide] for further information.
+This extension includes the 
https://quarkus.io/guides/openapi-swaggerui#dev-mode[Quarkus Swagger UI] for 
development.
+
+Providing you set a configuration property `camel.rest.api-context-path` in 
`application.properties`, Camel REST DSL endpoints will automatically become 
available within the Swagger UI so that you can interact with them.
+
+If you choose to expose Quarkus OpenAPI specifications alongside those from 
Camel, you can register them with the Swagger UI with configuration 
`quarkus.swagger-ui.urls."Quarkus"=/q/openapi`.
+
+[id="extensions-openapi-java-usage-integration-with-quarkus-openapi"]
+=== Integration with Quarkus OpenAPI
+
+By default, Camel REST service OpenAPI specifications are exposed under a 
separate HTTP endpoint to those generated by Quarkus OpenAPI.
+
+You can enable Camel REST services to be exposed on the Quarkus OpenAPI 
endpoint with the following configuration.
 
-This is an experimental feature. You can enable it by
 [source, properties]
 ----
 quarkus.camel.openapi.expose.enabled=true
 ----
 
+When `quarkus-smallrye-openapi` is added to the application dependencies, the 
OpenAPI specification can be accessed from the following path 
`/q/openapi?format=json`.
+
+Refer to the https://quarkus.io/guides/openapi-swaggerui[Quarkus OpenAPI 
guide] for further information.
+
 [WARNING]
 ====
-It's the user's responsibility to use `@RegisterForReflection` to register all 
model classes for reflection.
+It's the users responsibility to use `@RegisterForReflection` to register all 
model classes for reflection.
+
+This feature does not support REST services defined by implementations of 
`org.apache.camel.builder.LambdaRouteBuilder`.
 
-It doesn't support the rest services used in 
`org.apache.camel.builder.LambdaRouteBuilder` right now.
-Also, it can not use CDI injection in the RouteBuilder `configure()` since we 
get the rest definitions at build time while CDI is unavailable.
+Usage of CDI injection within the RouteBuilder `configure()` method must also 
be avoided, since CDI is unavailable at build time.
 ====
 
 
diff --git a/extensions/openapi-java/deployment/pom.xml 
b/extensions/openapi-java/deployment/pom.xml
index 987565ce54..123b3aba01 100644
--- a/extensions/openapi-java/deployment/pom.xml
+++ b/extensions/openapi-java/deployment/pom.xml
@@ -46,6 +46,10 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-support-swagger-deployment</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-swagger-ui-deployment</artifactId>
+        </dependency>
         <dependency>
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-resteasy</artifactId>
diff --git 
a/extensions/openapi-java/deployment/src/main/java/org/apache/camel/quarkus/component/openapi/java/deployment/OpenApiJavaProcessor.java
 
b/extensions/openapi-java/deployment/src/main/java/org/apache/camel/quarkus/component/openapi/java/deployment/OpenApiJavaProcessor.java
index e45b6d25fc..4d90e3e150 100644
--- 
a/extensions/openapi-java/deployment/src/main/java/org/apache/camel/quarkus/component/openapi/java/deployment/OpenApiJavaProcessor.java
+++ 
b/extensions/openapi-java/deployment/src/main/java/org/apache/camel/quarkus/component/openapi/java/deployment/OpenApiJavaProcessor.java
@@ -39,6 +39,7 @@ import io.quarkus.deployment.annotations.BuildStep;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
 import 
io.quarkus.smallrye.openapi.deployment.spi.AddToOpenAPIDefinitionBuildItem;
+import io.quarkus.swaggerui.deployment.SwaggerUiUrlBuildItem;
 import io.smallrye.openapi.api.util.MergeUtil;
 import io.smallrye.openapi.runtime.io.IOContext;
 import io.smallrye.openapi.runtime.io.JsonIO;
@@ -136,6 +137,16 @@ class OpenApiJavaProcessor {
         }
     }
 
+    @BuildStep(onlyIfNot = ExposeOpenApiEnabled.class)
+    void registerSwaggerUICamelUrl(BuildProducer<SwaggerUiUrlBuildItem> 
swaggerUiUrl) {
+        Config config = ConfigProvider.getConfig();
+        config.getOptionalValue("camel.rest.apiContextPath", String.class)
+                .or(() -> 
config.getOptionalValue("camel.rest.api-context-path", String.class))
+                .ifPresent(apiContextPath -> {
+                    swaggerUiUrl.produce(new SwaggerUiUrlBuildItem("Camel", 
apiContextPath));
+                });
+    }
+
     public static final class ExposeOpenApiEnabled implements BooleanSupplier {
         OpenApiJavaBuildTimeConfig config;
 
diff --git 
a/extensions/openapi-java/deployment/src/test/java/org/apache/camel/quarkus/component/openapi/java/deployment/SwaggerCamelUrlTest.java
 
b/extensions/openapi-java/deployment/src/test/java/org/apache/camel/quarkus/component/openapi/java/deployment/SwaggerCamelUrlTest.java
new file mode 100644
index 0000000000..51827ad56f
--- /dev/null
+++ 
b/extensions/openapi-java/deployment/src/test/java/org/apache/camel/quarkus/component/openapi/java/deployment/SwaggerCamelUrlTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.quarkus.component.openapi.java.deployment;
+
+import java.util.List;
+
+import io.quarkus.builder.Version;
+import io.quarkus.maven.dependency.Dependency;
+import io.quarkus.test.QuarkusUnitTest;
+import io.restassured.RestAssured;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.hamcrest.Matchers.containsString;
+
+public class SwaggerCamelUrlTest {
+    @RegisterExtension
+    static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+            .setForcedDependencies(List.of(
+                    Dependency.of("io.quarkus", "quarkus-swagger-ui", 
Version.getVersion())))
+            .overrideConfigKey("camel.rest.apiContextPath", "/camel/openapi")
+            .overrideConfigKey("quarkus.swagger-ui.urls-primary-name", "camel")
+            .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
+                    .addClasses(RestRoutes.class, QuarkusResource.class)
+                    .addAsResource("routes/rests.xml", "routes/rests.xml")
+                    .addAsResource("routes/routes.xml", "routes/routes.xml"));
+
+    @Test
+    void swaggerUiContainsCamelApiContextPath() {
+        RestAssured.given()
+                .get("/q/swagger-ui")
+                .then()
+                .statusCode(200)
+                .body(containsString(" url: '/camel/openapi'"));
+    }
+}
diff --git a/extensions/openapi-java/runtime/pom.xml 
b/extensions/openapi-java/runtime/pom.xml
index 9d557658a6..edf2ec66d2 100644
--- a/extensions/openapi-java/runtime/pom.xml
+++ b/extensions/openapi-java/runtime/pom.xml
@@ -48,6 +48,10 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-support-swagger</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-swagger-ui</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/extensions/openapi-java/runtime/src/main/doc/usage.adoc 
b/extensions/openapi-java/runtime/src/main/doc/usage.adoc
index 4e7506a251..d61012170e 100644
--- a/extensions/openapi-java/runtime/src/main/doc/usage.adoc
+++ b/extensions/openapi-java/runtime/src/main/doc/usage.adoc
@@ -1,18 +1,31 @@
-You can use this extension to expose REST DSL services to Quarkus OpenAPI. With
-`quarkus-smallrye-openapi`, you can access them by `/q/openapi?format=json`.
+=== Swagger UI for development
 
-Refer to the https://quarkus.io/guides/openapi-swaggerui[Quarkus OpenAPI 
guide] for further information.
+This extension includes the 
https://quarkus.io/guides/openapi-swaggerui#dev-mode[Quarkus Swagger UI] for 
development.
+
+Providing you set a configuration property `camel.rest.api-context-path` in 
`application.properties`, Camel REST DSL endpoints will automatically become 
available within the Swagger UI so that you can interact with them.
+
+If you choose to expose Quarkus OpenAPI specifications alongside those from 
Camel, you can register them with the Swagger UI with configuration 
`quarkus.swagger-ui.urls."Quarkus"=/q/openapi`.
+
+=== Integration with Quarkus OpenAPI
+
+By default, Camel REST service OpenAPI specifications are exposed under a 
separate HTTP endpoint to those generated by Quarkus OpenAPI.
+
+You can enable Camel REST services to be exposed on the Quarkus OpenAPI 
endpoint with the following configuration.
 
-This is an experimental feature. You can enable it by
 [source, properties]
 ----
 quarkus.camel.openapi.expose.enabled=true
 ----
 
+When `quarkus-smallrye-openapi` is added to the application dependencies, the 
OpenAPI specification can be accessed from the following path 
`/q/openapi?format=json`.
+
+Refer to the https://quarkus.io/guides/openapi-swaggerui[Quarkus OpenAPI 
guide] for further information.
+
 [WARNING]
 ====
-It's the user's responsibility to use `@RegisterForReflection` to register all 
model classes for reflection.
+It's the users responsibility to use `@RegisterForReflection` to register all 
model classes for reflection.
+
+This feature does not support REST services defined by implementations of 
`org.apache.camel.builder.LambdaRouteBuilder`.
 
-It doesn't support the rest services used in 
`org.apache.camel.builder.LambdaRouteBuilder` right now.
-Also, it can not use CDI injection in the RouteBuilder `configure()` since we 
get the rest definitions at build time while CDI is unavailable.
+Usage of CDI injection within the RouteBuilder `configure()` method must also 
be avoided, since CDI is unavailable at build time.
 ====

Reply via email to