You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2026/07/16 13:39:53 UTC
(camel) branch main updated: CAMEL-24115: camel-rest-openapi - Write generated operationId back to Operation for dispatch (#24781)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 63dbd043956b CAMEL-24115: camel-rest-openapi - Write generated operationId back to Operation for dispatch (#24781)
63dbd043956b is described below
commit 63dbd043956b42e786cff510689a0fbe44d17a66
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 16 15:39:37 2026 +0200
CAMEL-24115: camel-rest-openapi - Write generated operationId back to Operation for dispatch (#24781)
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
.../DefaultRestOpenapiProcessorStrategy.java | 6 +++-
.../openapi/RestOpenapiProcessorStrategyTest.java | 38 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java
index ebf6c45b4d5f..43b6056540c8 100644
--- a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java
+++ b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java
@@ -83,7 +83,11 @@ public class DefaultRestOpenapiProcessorStrategy extends ServiceSupport
for (var e : openAPI.getPaths().entrySet()) {
for (var o : e.getValue().readOperationsMap().entrySet()) {
Operation op = o.getValue();
- String id = op.getOperationId() != null ? op.getOperationId() : generateOperationId(e.getKey(), o.getKey());
+ String id = op.getOperationId();
+ if (id == null) {
+ id = generateOperationId(e.getKey(), o.getKey());
+ op.setOperationId(id);
+ }
ids.add(component + "://" + id);
}
}
diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategyTest.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategyTest.java
index 567c48352626..54dc21d2d39e 100644
--- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategyTest.java
+++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategyTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.rest.openapi;
import io.swagger.v3.oas.models.OpenAPI;
+import io.swagger.v3.oas.models.Operation;
import org.apache.camel.CamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
@@ -50,6 +51,43 @@ class RestOpenapiProcessorStrategyTest extends ManagedCamelTestSupport {
}
+ @Test
+ void testMissingOperationIdSetsGeneratedIdOnOperation() throws Exception {
+ // Add routes matching the generated GENOPID names so validation passes
+ camelContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:GENOPID_GET.users").setBody(constant("ok"));
+ from("direct:GENOPID_GET.user._id_").setBody(constant("ok"));
+ }
+ });
+
+ DefaultRestOpenapiProcessorStrategy strategy = new DefaultRestOpenapiProcessorStrategy();
+ strategy.setCamelContext(camelContext);
+ strategy.setMissingOperation("fail");
+
+ OpenAPI openAPI = getOpenApi();
+
+ // Verify operationIds are initially null
+ for (var entry : openAPI.getPaths().entrySet()) {
+ for (Operation op : entry.getValue().readOperations()) {
+ assertNull(op.getOperationId(),
+ "operationId should be null initially for path: " + entry.getKey());
+ }
+ }
+
+ // Validation should pass since routes match the generated IDs
+ strategy.validateOpenApi(openAPI, null, mock(PlatformHttpConsumerAware.class));
+
+ // Verify generated operationIds were written back to the Operations
+ // so that process() can dispatch to the correct direct endpoint
+ Operation usersOp = openAPI.getPaths().get("/users").getGet();
+ assertEquals("GENOPID_GET.users", usersOp.getOperationId());
+
+ Operation userByIdOp = openAPI.getPaths().get("/user/{id}").getGet();
+ assertEquals("GENOPID_GET.user._id_", userByIdOp.getOperationId());
+ }
+
private OpenAPI getOpenApi() {
return RestOpenApiEndpoint.loadSpecificationFrom(camelContext, "missing-opid.yaml");
}