davsclaus commented on code in PR #28241: URL: https://github.com/apache/camel/pull/28241#discussion_r4340700748
########## tooling/spi-annotations/src/main/java/org/apache/camel/spi/BodyType.java: ########## @@ -0,0 +1,153 @@ +/* + * 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.spi; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * One side of {@link BodyTypes}: the body a step needs or leaves. + * <p/> + * The carriers are coarse on purpose: a carrier that is right is better than a precise Java type that is wrong. Give + * the {@link #javaType()} only when the body is always of that type. + * + * @since 4.24 + */ +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Target({}) +public @interface BodyType { + + /** + * The carriers of the body: the kinds of Java object it is in. Several for a body that can be any of them. None + * when the side is not known. + */ + Carrier[] value() default {}; + + /** + * The Java type of the body, when it is always of this type, such as + * {@code org.apache.camel.component.file.GenericFile}. + */ + String javaType() default ""; + + /** + * The format of the payload, when it is always the same: json, xml, csv, yaml, text or binary. These are the names + * of the data types of Kamelets. + */ + String format() default ""; + + /** + * The options the body depends on. The carriers hold while these options keep their default values; with another + * value the body is not known, unless {@link #byOption()} says it. + */ + String[] dependsOn() default {}; + + /** + * The body for other values of an option, such as {@code output=bytes}. + */ + When[] byOption() default {}; + + /** + * What to know about the body, in a sentence for the documentation and the tools. + */ + String description() default ""; + + /** + * The body when an option has a value. + */ + @Retention(RetentionPolicy.RUNTIME) + @Documented + @Target({}) + @interface When { + + /** + * The name of the option. + */ + String option(); + + /** + * The value of the option. + */ + String value(); + + /** + * The carriers of the body with this value. + */ + Carrier[] carrier(); Review Comment: Agreed, thanks: done in https://github.com/apache/camel/pull/28241/commits/0be66c57fb11. It is `When.carriers()` now, as the catalog JSON and `BodyTypeModel.getCarriers()` name it. - The annotations of the stacked PRs use the new name too: #28242 in https://github.com/apache/camel/pull/28242/commits/15aaf465fa04 and #28250 in https://github.com/apache/camel/pull/28250/commits/1ef9d76dc353. - The generated JSON does not change, as the catalog already called the field `carriers`. _Claude Code on behalf of davsclaus_ ########## tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BodyTypeModel.java: ########## @@ -0,0 +1,193 @@ +/* + * 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.tooling.model; + +import java.util.ArrayList; +import java.util.List; + +/** + * One side of the body types of a component, data format or language: the body a step needs, or the body it leaves + * after it, with the default options (CAMEL-24961). + * <p/> + * The carriers are the kinds of Java object the body is in: null, text, bytes, stream, file, value, map, list, iterator + * and pojo; unchanged for a step that leaves the body as it was, any for a step that takes any body, and unknown for a + * body that depends on what the other system sends or on a class the user configures. + */ +public class BodyTypeModel { + + /** The body of the message the consumer creates. */ + public static final String CONSUMER_OUT = "consumerOut"; + /** The bodies a consumer that answers the caller can reply with: the body the route ends with. */ + public static final String CONSUMER_REPLY = "consumerReply"; + /** The bodies the producer can send or write. */ + public static final String PRODUCER_IN = "producerIn"; + /** The body after the producer. */ + public static final String PRODUCER_OUT = "producerOut"; + /** The bodies a data format can marshal. */ + public static final String MARSHAL_IN = "marshalIn"; + /** The body after marshal. */ + public static final String MARSHAL_OUT = "marshalOut"; + /** The bodies a data format can unmarshal. */ + public static final String UNMARSHAL_IN = "unmarshalIn"; + /** The body after unmarshal. */ + public static final String UNMARSHAL_OUT = "unmarshalOut"; + /** The bodies the expressions of a language can read. */ + public static final String EXPRESSION_IN = "expressionIn"; + /** The result of an expression of a language. */ + public static final String EXPRESSION_OUT = "expressionOut"; + + private List<String> carriers = new ArrayList<>(); + private String javaType; + private String format; + private List<String> dependsOn = new ArrayList<>(); + private List<OptionBodyTypeModel> byOption = new ArrayList<>(); + private String description; + + /** + * The carriers of the body: one, or several for a body that can be any of them. + */ + public List<String> getCarriers() { + return carriers; + } + + public void setCarriers(List<String> carriers) { + this.carriers = carriers; + } + + /** + * The Java type of the body, when it is always of this type. + */ + public String getJavaType() { + return javaType; + } + + public void setJavaType(String javaType) { + this.javaType = javaType; + } + + /** + * The format of the payload, when it is always the same: json, xml, csv, yaml, text or binary. + */ + public String getFormat() { + return format; + } + + public void setFormat(String format) { + this.format = format; + } + + /** + * The options the body depends on: with another value than the default the body is not known, unless + * {@link #getByOption()} says it. + */ + public List<String> getDependsOn() { + return dependsOn; + } + + public void setDependsOn(List<String> dependsOn) { + this.dependsOn = dependsOn; + } + + /** + * The body for other values of an option. + */ + public List<OptionBodyTypeModel> getByOption() { + return byOption; + } + + public void setByOption(List<OptionBodyTypeModel> byOption) { + this.byOption = byOption; + } + + /** + * What to know about the body, in a sentence. + */ + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /** + * Whether the body is left as it was (for the body after a step). + */ + public boolean isUnchanged() { + return carriers.contains("unchanged"); + } + + /** + * Whether the body is not known without the configuration or the data of the other system. + */ + public boolean isUnknown() { + return carriers.isEmpty() || carriers.contains("unknown"); Review Comment: Done in https://github.com/apache/camel/pull/28241/commits/0be66c57fb11. The Javadoc now says that a side with no carriers is unknown too: the build rejects one, but a catalog from elsewhere, such as JSON written by hand, can have it. _Claude Code on behalf of davsclaus_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
