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 78ffde7d1788 CAMEL-27979: camel-jbang - optionsFilter=<header name>
answers with the headers again when option descriptions name them (#31205)
78ffde7d1788 is described below
commit 78ffde7d178809d5c9ab5e1ae31031fcca26b386
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Dec 1 23:21:06 2026 +0100
CAMEL-27979: camel-jbang - optionsFilter=<header name> answers with the
headers again when option descriptions name them (#31205)
camel_catalog_doc (Camel CLI and Camel MCP) searches the message headers of
a component only when optionsFilter matches no option. Since option
descriptions name headers (CAMEL-23832), optionsFilter=CamelAwsS3Key on aws2-s3
returned the options keyName and deleteAfterRead instead of the header,
although headersHint says optionsFilter=<header name> returns the header. This
broke CatalogLookupsTest and CatalogDocSeveralOptionsTest on main.
In CatalogDocs.putComponentOptions, when a single filter term is contained
in the name of a message header of the component, an option that matches the
term only where its description names such a header no longer counts as a
match. The answer goes to the headers again, and the note names the options
that mention the header. A match in the option name, group, label or elsewhere
in the description still counts. With several terms, each term that only names
a header is reported in unmat [...]
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../dsl/jbang/core/commands/ai/CatalogDocs.java | 61 ++++++++++++++++++++--
.../commands/ai/CatalogDocSeveralOptionsTest.java | 8 +--
.../jbang/core/commands/ai/CatalogLookupsTest.java | 38 +++++++-------
3 files changed, 79 insertions(+), 28 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java
index b3922fdc6687..aacaa924f15e 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java
@@ -2292,6 +2292,12 @@ public final class CatalogDocs {
}
Set<String> endpointListed = new HashSet<>();
Set<String> endpointOmitted = new HashSet<>();
+ // a filter that is (part of) the name of a message header asks for
headers: an option that matches it only where
+ // its description names such a header (keyName and deleteAfterRead of
aws2-s3 name CamelAwsS3Key) is no match,
+ // else the headers would never be returned, and the note names such
options (CAMEL-27979)
+ List<String> headerNames
+ = filter != null && !several(filter) ?
headerNamesContaining(model, filter) : List.of();
+ Set<String> mentionedBy = new LinkedHashSet<>();
for (String optionScope : List.of("endpoint", "component")) {
List<? extends BaseOptionModel> options
= "endpoint".equals(optionScope) ?
model.getEndpointOptions() : model.getComponentOptions();
@@ -2302,6 +2308,10 @@ public final class CatalogDocs {
if (!matchesOptionFilter(opt, filter)) {
continue;
}
+ if (!headerNames.isEmpty() && onlyNamesHeaders(opt, filter,
headerNames)) {
+ mentionedBy.add(opt.getName());
+ continue;
+ }
boolean endpoint = "endpoint".equals(optionScope);
if (!endpoint && endpointListed.contains(opt.getName())) {
// already listed with its endpoint twin
@@ -2364,7 +2374,7 @@ public final class CatalogDocs {
if (filter != null && !several(filter) && ordered.isEmpty() && omitted
== 0) {
List<ComponentModel.EndpointHeaderModel> headers =
headersMatching(model, filter);
if (!headers.isEmpty()) {
- putMatchedHeaders(result, headers, filter);
+ putMatchedHeaders(result, headers, filter, mentionedBy);
} else {
// an empty list read as "not supported" (smtp + tls, xslt +
param): say that nothing matched, and
// where else to look
@@ -2397,6 +2407,39 @@ public final class CatalogDocs {
/** Up to this many message headers that a filter matches are listed in
full; more are listed by name. */
static final int MATCHED_HEADERS_LIMIT = 10;
+ /** The names of the message headers of a component that contain the
filter, in lower case and the longest first. */
+ private static List<String> headerNamesContaining(ComponentModel model,
String filter) {
+ List<String> answer = new ArrayList<>();
+ if (model.getEndpointHeaders() != null) {
+ for (ComponentModel.EndpointHeaderModel h :
model.getEndpointHeaders()) {
+ String name = h.getName() != null ?
h.getName().toLowerCase(Locale.ROOT) : "";
+ if (name.contains(filter)) {
+ answer.add(name);
+ }
+ }
+ }
+ // CamelAwsS3KeysToDelete is taken out of a description before
CamelAwsS3Key
+ answer.sort(Comparator.comparingInt(String::length).reversed());
+ return answer;
+ }
+
+ /** Whether an option matches the filter only where its description names
one of these headers. */
+ private static boolean onlyNamesHeaders(BaseOptionModel opt, String
filter, List<String> headerNames) {
+ if (opt.getDescription() == null || containsLower(opt.getName(),
filter) || containsLower(opt.getGroup(), filter)
+ || containsLower(opt.getLabel(), filter)) {
+ return false;
+ }
+ String text = opt.getDescription().toLowerCase(Locale.ROOT);
+ for (String name : headerNames) {
+ text = text.replace(name, " ");
+ }
+ return !text.contains(filter);
+ }
+
+ private static boolean containsLower(String text, String filter) {
+ return text != null && text.toLowerCase(Locale.ROOT).contains(filter);
+ }
+
/**
* The message headers of a component that a filter matches, by name
before by description. A header is not an
* option, and the filter searched the options only: a model sent
optionsFilter=CamelAwsS3Key on aws2-s3 17 times in
@@ -2430,7 +2473,8 @@ public final class CatalogDocs {
* options.
*/
private static void putMatchedHeaders(
- JsonObject result, List<ComponentModel.EndpointHeaderModel>
headers, String filter) {
+ JsonObject result, List<ComponentModel.EndpointHeaderModel>
headers, String filter,
+ Set<String> mentionedBy) {
boolean many = headers.size() > MATCHED_HEADERS_LIMIT;
JsonArray full = new JsonArray();
JsonArray names = new JsonArray();
@@ -2442,10 +2486,17 @@ public final class CatalogDocs {
}
}
String see = full.isEmpty() ? "headerNames" : names.isEmpty() ?
"headers" : "headers and headerNames";
- result.put("note", "no option matches '" + filter + "', but " +
(headers.size() == 1
+ String note = "no option matches '" + filter + "', but " +
(headers.size() == 1
? "a message header does" : headers.size() + " message headers
do")
- + ": see " + see + ". A header is not set on the
URI: set it on the message before a to:"
- + " (setHeader), or read it after a from:
(${header." + headers.get(0).getName() + "})");
+ + ": see " + see + ". A header is not set on the URI:
set it on the message before a to:"
+ + " (setHeader), or read it after a from: (${header." +
headers.get(0).getName() + "})";
+ if (!mentionedBy.isEmpty()) {
+ note += ". " + (mentionedBy.size() == 1 ? "The option " : "The
options ") + String.join(", ", mentionedBy)
+ + (mentionedBy.size() == 1 ? " names " : " name ")
+ + (headers.get(0).getName().equalsIgnoreCase(filter) ?
headers.get(0).getName() : "such a header")
+ + " in the description (optionsFilter=<option name>
returns an option)";
+ }
+ result.put("note", note);
if (!full.isEmpty()) {
result.put("headers", full);
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocSeveralOptionsTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocSeveralOptionsTest.java
index a9969f750a39..8a7bcbbd1164 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocSeveralOptionsTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocSeveralOptionsTest.java
@@ -97,10 +97,10 @@ class CatalogDocSeveralOptionsTest {
@Test
void aTermThatIsAMessageHeaderSaysSo() throws Exception {
- JsonObject answer = catalogDoc(Map.of("name", "aws2-s3",
"optionsFilter", "bucketNameOrArn,CamelAwsS3GrantRead"));
+ JsonObject answer = catalogDoc(Map.of("name", "aws2-s3",
"optionsFilter", "bucketNameOrArn,CamelAwsS3Key"));
assertThat(names(answer, "options")).contains("bucketNameOrArn");
- JsonObject term = unmatched(answer, "camelawss3grantread");
- assertThat(names(term, "headers")).contains("CamelAwsS3GrantRead");
+ JsonObject term = unmatched(answer, "camelawss3key");
+ assertThat(names(term, "headers")).contains("CamelAwsS3Key");
assertThat(term.getString("note")).contains("message headers do");
assertThat(answer.get("matchedHeaders")).isNull();
}
@@ -141,7 +141,7 @@ class CatalogDocSeveralOptionsTest {
assertThat(names(one, "closestOptions")).contains("dataSource");
assertThat(one.get("unmatchedTerms")).isNull();
- JsonObject header = catalogDoc(Map.of("name", "aws2-s3",
"optionsFilter", "CamelAwsS3GrantRead"));
+ JsonObject header = catalogDoc(Map.of("name", "aws2-s3",
"optionsFilter", "CamelAwsS3Key"));
assertThat(header.getInteger("matchedHeaders")).isPositive();
assertThat(header.get("unmatchedTerms")).isNull();
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogLookupsTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogLookupsTest.java
index b54abe1a8200..d6b6d34af55f 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogLookupsTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogLookupsTest.java
@@ -57,34 +57,35 @@ class CatalogLookupsTest {
@Test
void aFilterThatMatchesNoOptionFindsTheMessageHeaders() throws Exception {
- // a model sent optionsFilter=CamelAwsS3Key on aws2-s3 17 times in one
step, when no option matched it; the
- // keyName option now names that header, so a header that no option
mentions stands in for it
- JsonObject answer = catalogDoc(Map.of("name", "aws2-s3",
"optionsFilter", "CamelAwsS3GrantRead"));
+ // a model sent optionsFilter=CamelAwsS3Key on aws2-s3 17 times in one
step, and no option matches it
+ JsonObject answer = catalogDoc(Map.of("name", "aws2-s3",
"optionsFilter", "CamelAwsS3Key"));
assertThat(answer.getInteger("matchedOptions")).isZero();
- assertThat(answer.getInteger("matchedHeaders")).isEqualTo(2);
+ assertThat(answer.getInteger("matchedHeaders")).isEqualTo(3);
// the header the filter names comes first, with what the catalog says
of it
JsonObject key = first(answer, "headers");
- assertThat(key.getString("name")).isEqualTo("CamelAwsS3GrantRead");
- assertThat(key.getString("constantName"))
-
.isEqualTo("org.apache.camel.component.aws2.s3.AWS2S3Constants#GRANT_READ");
+ assertThat(key.getString("name")).isEqualTo("CamelAwsS3Key");
+
assertThat(key.getString("constantName")).isEqualTo("org.apache.camel.component.aws2.s3.AWS2S3Constants#KEY");
assertThat(key.getString("javaType")).isEqualTo("String");
- assertThat(key.getString("group")).isEqualTo("producer");
- assertThat(key.getString("description")).contains("grantee");
- assertThat(answer.getString("note")).contains("2 message headers do",
"${header.CamelAwsS3GrantRead}");
+ assertThat(key.getString("group")).isEqualTo("common");
+ assertThat(key.getString("description")).contains("key");
+ assertThat(answer.getString("note")).contains("3 message headers do",
"${header.CamelAwsS3Key}");
assertThat(answer.get("closestOptions")).isNull();
+ // CAMEL-27979: keyName and deleteAfterRead name the header in their
description, which does not make them a
+ // match of a filter that is the name of a header, else the header
would never be returned; the note says so
+ assertThat(names(answer, "options")).isEmpty();
+ assertThat(answer.getString("note")).contains("keyName",
"deleteAfterRead", "name CamelAwsS3Key");
// with includeHeaders the headers the filter matches, not all of them
(54, cut at the end of the answer)
JsonObject included
- = catalogDoc(Map.of("name", "aws2-s3", "optionsFilter",
"CamelAwsS3GrantRead", "includeHeaders", "true"));
- assertThat(names(included,
"headers")).containsExactly("CamelAwsS3GrantRead", "CamelAwsS3GrantReadACP");
+ = catalogDoc(Map.of("name", "aws2-s3", "optionsFilter",
"CamelAwsS3Key", "includeHeaders", "true"));
+ assertThat(names(included,
"headers")).containsExactly("CamelAwsS3Key", "CamelAwsS3KeysToDelete",
+ "CamelAwsS3ProducedKey");
// a filter that matches many headers lists their names, so the answer
stays short
- // (aws2-transcribe: no option of it mentions its header prefix,
unlike aws2-s3 whose keyName names a header)
- JsonObject many = catalogDoc(Map.of("name", "aws2-transcribe",
"optionsFilter", "CamelAwsTranscribe"));
+ JsonObject many = catalogDoc(Map.of("name", "aws2-s3",
"optionsFilter", "CamelAwsS3"));
assertThat(many.getInteger("matchedHeaders")).isGreaterThan(CatalogDocs.MATCHED_HEADERS_LIMIT);
assertThat(many.get("headers")).isNull();
- assertThat(strings(many, "headerNames"))
- .contains("CamelAwsTranscribeTranscriptionJobName",
"CamelAwsTranscribeLanguageCode");
+ assertThat(strings(many, "headerNames")).contains("CamelAwsS3Key",
"CamelAwsS3ContentType");
assertThat(many.getString("headersHint")).contains("optionsFilter=<header
name>");
// a filter that matches an option is answered as before, without
headers
@@ -196,9 +197,8 @@ class CatalogLookupsTest {
+ " name in
moreHeaders; optionsFilter=<header name>"
+ " returns
one in full");
// and the filter the note gives returns the header
- JsonObject key
- = catalogDoc(Map.of("name", "aws2-s3", "kind", "component",
"optionsFilter", "CamelAwsS3GrantRead"));
- assertThat(first(key,
"headers").getString("name")).isEqualTo("CamelAwsS3GrantRead");
+ JsonObject key = catalogDoc(Map.of("name", "aws2-s3", "kind",
"component", "optionsFilter", "CamelAwsS3Key"));
+ assertThat(first(key,
"headers").getString("name")).isEqualTo("CamelAwsS3Key");
}
@Test