This is an automated email from the ASF dual-hosted git repository.
fmariani pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 295fc98a5fb7 CAMEL-23243: Convert OpenAI operation property from
String to enum
295fc98a5fb7 is described below
commit 295fc98a5fb7a29670f3de971c0432af16e0e4c8
Author: Croway <[email protected]>
AuthorDate: Thu Apr 9 17:31:19 2026 +0200
CAMEL-23243: Convert OpenAI operation property from String to enum
---
.../apache/camel/catalog/components/openai.json | 2 +-
.../org/apache/camel/component/openai/openai.json | 2 +-
.../camel/component/openai/OpenAIComponent.java | 2 +-
.../camel/component/openai/OpenAIEndpoint.java | 15 +++----
.../camel/component/openai/OpenAIOperations.java | 48 ++++++++++++++++++++++
.../builder/endpoint/StaticEndpointBuilders.java | 4 ++
.../endpoint/dsl/OpenAIEndpointBuilderFactory.java | 4 ++
7 files changed, 65 insertions(+), 12 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/openai.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/openai.json
index 4f17761de15e..854171657f51 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/openai.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/openai.json
@@ -59,7 +59,7 @@
"CamelOpenAIOriginalText": { "index": 24, "kind": "header", "displayName":
"", "group": "producer", "label": "", "required": false, "javaType": "String or
List<String>", "deprecated": false, "deprecationNote": "", "autowired": false,
"secret": false, "description": "Original text content when embeddings
operation is used", "constantName":
"org.apache.camel.component.openai.OpenAIConstants#ORIGINAL_TEXT" }
},
"properties": {
- "operation": { "index": 0, "kind": "path", "displayName": "Operation",
"group": "producer", "label": "", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "description": "The operation to perform:
'chat-completion' or 'embeddings'" },
+ "operation": { "index": 0, "kind": "path", "displayName": "Operation",
"group": "producer", "label": "", "required": true, "type": "enum", "javaType":
"org.apache.camel.component.openai.OpenAIOperations", "enum": [
"chat-completion", "embeddings" ], "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "description": "The operation to perform:
'chat-completion' or 'embeddings'" },
"additionalBodyProperty": { "index": 1, "kind": "parameter",
"displayName": "Additional Body Property", "group": "producer", "label": "",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix":
"additionalBodyProperty.", "multiValue": true, "deprecated": false,
"deprecationNote": "", "autowired": false, "secret": false,
"configurationClass": "org.apache.camel.component.openai.OpenAIConfiguration",
"configurationField": "configur [...]
"apiKey": { "index": 2, "kind": "parameter", "displayName": "Api Key",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": true, "configurationClass":
"org.apache.camel.component.openai.OpenAIConfiguration", "configurationField":
"configuration", "description": "OpenAI API key. Can also be set via
OPENAI_API_KEY environment variable." },
"baseUrl": { "index": 3, "kind": "parameter", "displayName": "Base Url",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "defaultValue":
"https:\/\/api.openai.com\/v1", "configurationClass":
"org.apache.camel.component.openai.OpenAIConfiguration", "configurationField":
"configuration", "description": "Base URL for OpenAI API. Defaults to OpenAI's
off [...]
diff --git
a/components/camel-ai/camel-openai/src/generated/resources/META-INF/org/apache/camel/component/openai/openai.json
b/components/camel-ai/camel-openai/src/generated/resources/META-INF/org/apache/camel/component/openai/openai.json
index 4f17761de15e..854171657f51 100644
---
a/components/camel-ai/camel-openai/src/generated/resources/META-INF/org/apache/camel/component/openai/openai.json
+++
b/components/camel-ai/camel-openai/src/generated/resources/META-INF/org/apache/camel/component/openai/openai.json
@@ -59,7 +59,7 @@
"CamelOpenAIOriginalText": { "index": 24, "kind": "header", "displayName":
"", "group": "producer", "label": "", "required": false, "javaType": "String or
List<String>", "deprecated": false, "deprecationNote": "", "autowired": false,
"secret": false, "description": "Original text content when embeddings
operation is used", "constantName":
"org.apache.camel.component.openai.OpenAIConstants#ORIGINAL_TEXT" }
},
"properties": {
- "operation": { "index": 0, "kind": "path", "displayName": "Operation",
"group": "producer", "label": "", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "description": "The operation to perform:
'chat-completion' or 'embeddings'" },
+ "operation": { "index": 0, "kind": "path", "displayName": "Operation",
"group": "producer", "label": "", "required": true, "type": "enum", "javaType":
"org.apache.camel.component.openai.OpenAIOperations", "enum": [
"chat-completion", "embeddings" ], "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "description": "The operation to perform:
'chat-completion' or 'embeddings'" },
"additionalBodyProperty": { "index": 1, "kind": "parameter",
"displayName": "Additional Body Property", "group": "producer", "label": "",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix":
"additionalBodyProperty.", "multiValue": true, "deprecated": false,
"deprecationNote": "", "autowired": false, "secret": false,
"configurationClass": "org.apache.camel.component.openai.OpenAIConfiguration",
"configurationField": "configur [...]
"apiKey": { "index": 2, "kind": "parameter", "displayName": "Api Key",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": true, "configurationClass":
"org.apache.camel.component.openai.OpenAIConfiguration", "configurationField":
"configuration", "description": "OpenAI API key. Can also be set via
OPENAI_API_KEY environment variable." },
"baseUrl": { "index": 3, "kind": "parameter", "displayName": "Base Url",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "defaultValue":
"https:\/\/api.openai.com\/v1", "configurationClass":
"org.apache.camel.component.openai.OpenAIConfiguration", "configurationField":
"configuration", "description": "Base URL for OpenAI API. Defaults to OpenAI's
off [...]
diff --git
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIComponent.java
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIComponent.java
index c3b77be8a807..d4b4b58d7230 100644
---
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIComponent.java
+++
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIComponent.java
@@ -61,7 +61,7 @@ public class OpenAIComponent extends DefaultComponent {
OpenAIEndpoint endpoint = new OpenAIEndpoint(uri, this, configuration);
// set the operation from the URI path (e.g., chat-completion)
- endpoint.setOperation(remaining);
+ endpoint.setOperation(OpenAIOperations.fromValue(remaining));
setProperties(endpoint, parameters);
return endpoint;
diff --git
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIEndpoint.java
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIEndpoint.java
index 0cafab2f472a..b9161ebedf52 100644
---
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIEndpoint.java
+++
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIEndpoint.java
@@ -42,9 +42,8 @@ import org.apache.camel.util.ObjectHelper;
public class OpenAIEndpoint extends DefaultEndpoint {
@UriPath
- @Metadata(required = true, description = "The operation to perform:
'chat-completion' or 'embeddings'",
- enums = "chat-completion,embeddings")
- private String operation;
+ @Metadata(required = true, description = "The operation to perform:
'chat-completion' or 'embeddings'")
+ private OpenAIOperations operation;
@UriParam
private OpenAIConfiguration configuration;
@@ -59,10 +58,8 @@ public class OpenAIEndpoint extends DefaultEndpoint {
@Override
public Producer createProducer() throws Exception {
return switch (operation) {
- case "chat-completion" -> new OpenAIProducer(this);
- case "embeddings" -> new OpenAIEmbeddingsProducer(this);
- default -> throw new IllegalArgumentException(
- "Unknown operation: " + operation + ". Supported:
chat-completion, embeddings");
+ case chatCompletion -> new OpenAIProducer(this);
+ case embeddings -> new OpenAIEmbeddingsProducer(this);
};
}
@@ -113,11 +110,11 @@ public class OpenAIEndpoint extends DefaultEndpoint {
return System.getProperty("openai.api.key");
}
- public String getOperation() {
+ public OpenAIOperations getOperation() {
return operation;
}
- public void setOperation(String operation) {
+ public void setOperation(OpenAIOperations operation) {
this.operation = operation;
}
diff --git
a/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIOperations.java
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIOperations.java
new file mode 100644
index 000000000000..ed8c8adc0f63
--- /dev/null
+++
b/components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIOperations.java
@@ -0,0 +1,48 @@
+/*
+ * 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.component.openai;
+
+public enum OpenAIOperations {
+
+ chatCompletion("chat-completion"),
+ embeddings("embeddings");
+
+ private final String value;
+
+ OpenAIOperations(String value) {
+ this.value = value;
+ }
+
+ public static OpenAIOperations fromValue(String value) {
+ for (OpenAIOperations op : values()) {
+ if (op.value.equalsIgnoreCase(value) ||
op.name().equalsIgnoreCase(value)) {
+ return op;
+ }
+ }
+ throw new IllegalArgumentException(
+ "Unknown operation: " + value + ". Supported: chat-completion,
embeddings");
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+}
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
index dc8a4503bc5b..fb6e7b3d11fa 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
@@ -12210,6 +12210,8 @@ public class StaticEndpointBuilders {
*
* Path parameter: operation (required)
* The operation to perform: 'chat-completion' or 'embeddings'
+ * There are 2 enums and the value can be one of: chat-completion,
+ * embeddings
*
* @param path operation
* @return the dsl builder
@@ -12229,6 +12231,8 @@ public class StaticEndpointBuilders {
*
* Path parameter: operation (required)
* The operation to perform: 'chat-completion' or 'embeddings'
+ * There are 2 enums and the value can be one of: chat-completion,
+ * embeddings
*
* @param componentName to use a custom component name for the endpoint
* instead of the default name
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpenAIEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpenAIEndpointBuilderFactory.java
index e2f733d788a0..3809ee39d3c2 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpenAIEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpenAIEndpointBuilderFactory.java
@@ -546,6 +546,8 @@ public interface OpenAIEndpointBuilderFactory {
*
* Path parameter: operation (required)
* The operation to perform: 'chat-completion' or 'embeddings'
+ * There are 2 enums and the value can be one of: chat-completion,
+ * embeddings
*
* @param path operation
* @return the dsl builder
@@ -565,6 +567,8 @@ public interface OpenAIEndpointBuilderFactory {
*
* Path parameter: operation (required)
* The operation to perform: 'chat-completion' or 'embeddings'
+ * There are 2 enums and the value can be one of: chat-completion,
+ * embeddings
*
* @param componentName to use a custom component name for the endpoint
* instead of the default name