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-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 2802326e1 Fix #3250: the build fails for a Kamelet that does not
declare spec.dataTypes for its own side (#3317)
2802326e1 is described below
commit 2802326e164b468e0c970f2585b08a81f43dd633
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 15:10:28 2026 +0100
Fix #3250: the build fails for a Kamelet that does not declare
spec.dataTypes for its own side (#3317)
CatalogValidator checks that a source declares dataTypes.out, a sink
dataTypes.in and an action both. An empty `headers: {}` counts, with a
comment that says why there is no default (all of them have one since
the previous commit). The developer guide describes the rule.
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
docs/modules/ROOT/pages/development.adoc | 14 ++++++
.../kamelets/maven/plugin/CatalogValidator.java | 26 ++++++++++
.../maven/plugin/CatalogValidatorTest.java | 57 ++++++++++++++++++++++
3 files changed, 97 insertions(+)
diff --git a/docs/modules/ROOT/pages/development.adoc
b/docs/modules/ROOT/pages/development.adoc
index bd6289a6b..be542f276 100644
--- a/docs/modules/ROOT/pages/development.adoc
+++ b/docs/modules/ROOT/pages/development.adoc
@@ -496,6 +496,20 @@ the body after it is the body before it. See
xref:documenting.adoc#documenting-u
A source declares the headers it emits under `out`; a sink or action declares
the ones it
consumes under `in`.
+Every Kamelet declares its own side: `out` for a source, `in` for a sink, and
both for an action.
+The build fails when one is missing. A side that has nothing to transform and
no headers to list
+is an empty `headers: {}`, with a comment that says why there is no `default`,
so that leaving the
+default out is a decision and not an accident:
+
+[source,yaml]
+----
+ dataTypes:
+ # No 'default:' here on purpose: the Content-Type header is sent as the
content type of the
+ # request, and a default would replace it on every message. See #3117.
+ in:
+ headers: {}
+----
+
Declaring them is worth the few lines for two reasons:
* `KameletsCatalog.getKameletSupportedHeaders` answers from the declaration
wherever there is
diff --git
a/library/kamelets-maven-plugin/src/main/java/org/apache/camel/kamelets/maven/plugin/CatalogValidator.java
b/library/kamelets-maven-plugin/src/main/java/org/apache/camel/kamelets/maven/plugin/CatalogValidator.java
index eb54b3e2b..061483e95 100644
---
a/library/kamelets-maven-plugin/src/main/java/org/apache/camel/kamelets/maven/plugin/CatalogValidator.java
+++
b/library/kamelets-maven-plugin/src/main/java/org/apache/camel/kamelets/maven/plugin/CatalogValidator.java
@@ -233,6 +233,7 @@ public final class CatalogValidator {
verifyTemplateConvention(kamelets, errors);
verifyDependencies(kamelets, errors);
verifyCatalogVersion(kamelets, errors);
+ verifyDataTypes(kamelets, errors);
return errors;
}
@@ -547,6 +548,31 @@ public final class CatalogValidator {
}
}
+ /**
+ * Every Kamelet declares in {@code spec.dataTypes} what it takes and
gives on its own side: {@code out} for a
+ * source, {@code in} for a sink, both for an action. A Kamelet with
nothing to declare says so with an empty
+ * {@code headers: {}} block and a comment that gives the reason, so that
leaving it out is a decision and not an
+ * accident. See #3250 and docs/modules/ROOT/pages/development.adoc.
+ */
+ static void verifyDataTypes(List<KameletInfo> kamelets, List<String>
errors) {
+ for (KameletInfo k : kamelets) {
+ List<String> sides = switch (k.label(TYPE_LABEL)) {
+ case "source" -> List.of("out");
+ case "sink" -> List.of("in");
+ case "action" -> List.of("in", "out");
+ default -> List.of();
+ };
+ Map<String, Object> dataTypes = k.map(k.spec(), "dataTypes");
+ for (String side : sides) {
+ if (k.map(dataTypes, side) == null) {
+ errors.add("kamelet " + q(k.name) + " does not declare
spec.dataTypes." + side + ": declare what it "
+ + ("in".equals(side) ? "takes" : "gives") + ", or
an empty \"headers: {}\" with a comment"
+ + " that says why it has no default");
+ }
+ }
+ }
+ }
+
static void verifyUsedParams(List<KameletInfo> kamelets, List<String>
errors) {
for (KameletInfo k : kamelets) {
if (USED_PARAMS_EXEMPT.contains(k.name)) {
diff --git
a/library/kamelets-maven-plugin/src/test/java/org/apache/camel/kamelets/maven/plugin/CatalogValidatorTest.java
b/library/kamelets-maven-plugin/src/test/java/org/apache/camel/kamelets/maven/plugin/CatalogValidatorTest.java
index 301341ce3..3f3e69e20 100644
---
a/library/kamelets-maven-plugin/src/test/java/org/apache/camel/kamelets/maven/plugin/CatalogValidatorTest.java
+++
b/library/kamelets-maven-plugin/src/test/java/org/apache/camel/kamelets/maven/plugin/CatalogValidatorTest.java
@@ -106,6 +106,49 @@ public class CatalogValidatorTest {
assertEquals(List.of(), verifyReservedPropertyNames("region",
"lazyStart", "connectTimeout", "locationId"));
}
+ @Test
+ void aSourceWithoutDataTypes() {
+ assertEquals(List.of("kamelet \"a-source\" does not declare
spec.dataTypes.out: declare what it gives, or an"
+ + " empty \"headers: {}\" with a comment that says why it has
no default"),
+ verifyDataTypes("source", null));
+ }
+
+ @Test
+ void aSourceThatDeclaresOnlyEmptyHeaders() {
+ assertEquals(List.of(), verifyDataTypes("source", Map.of("out",
Map.of("headers", Map.of()))));
+ }
+
+ @Test
+ void aSinkThatDeclaresOnlyItsOutput() {
+ List<String> errors = verifyDataTypes("sink", Map.of("out",
Map.of("default", "json")));
+
+ assertEquals(1, errors.size());
+ assertTrue(errors.get(0).startsWith("kamelet \"a-sink\" does not
declare spec.dataTypes.in: declare what it"
+ + " takes"), errors.get(0));
+ }
+
+ @Test
+ void aSinkWithADefault() {
+ assertEquals(List.of(), verifyDataTypes("sink", Map.of("in",
Map.of("default", "binary"))));
+ }
+
+ @Test
+ void anActionNeedsBothSides() {
+ List<String> errors = verifyDataTypes("action", Map.of("in",
Map.of("default", "json")));
+
+ assertEquals(1, errors.size());
+ assertTrue(errors.get(0).contains("spec.dataTypes.out"),
errors.get(0));
+ assertEquals(2, verifyDataTypes("action", Map.of()).size());
+ }
+
+ @Test
+ void aSideWithoutAnyContentIsNotDeclared() {
+ Map<String, Object> dataTypes = new LinkedHashMap<>();
+ dataTypes.put("in", null);
+
+ assertEquals(1, verifyDataTypes("sink", dataTypes).size());
+ }
+
private static List<String> verifyReservedPropertyNames(String... names) {
Map<String, Object> properties = new LinkedHashMap<>();
for (String name : names) {
@@ -137,4 +180,18 @@ public class CatalogValidatorTest {
List.of(new CatalogValidator.KameletInfo("a-sink", new
File("a-sink.kamelet.yaml"), doc)), errors);
return errors;
}
+
+ private static List<String> verifyDataTypes(String type, Map<String,
Object> dataTypes) {
+ String name = "a-" + type;
+ Map<String, Object> spec = new LinkedHashMap<>();
+ if (dataTypes != null) {
+ spec.put("dataTypes", dataTypes);
+ }
+ Map<String, Object> doc = Map.of("metadata", Map.of("labels",
Map.of(CatalogValidator.TYPE_LABEL, type)),
+ "spec", spec);
+ List<String> errors = new ArrayList<>();
+ CatalogValidator.verifyDataTypes(
+ List.of(new CatalogValidator.KameletInfo(name, new File(name +
".kamelet.yaml"), doc)), errors);
+ return errors;
+ }
}