Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml default #16291

Merged
merged 7 commits into from
Nov 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public void testFromRestModel() throws Exception {
assertTrue(xml.contains("</rests>"));

assertTrue(xml.contains(
"<param defaultValue=\"1\" dataType=\"integer\" name=\"header_count\" description=\"header param description1\" type=\"header\" required=\"true\""));
"<param defaultValue=\"1\" dataType=\"integer\" name=\"header_count\" description=\"header param description1\" type=\"header\""));
assertTrue(xml.contains(
"<param defaultValue=\"b\" dataType=\"string\" name=\"header_letter\" description=\"header param description2\" type=\"query\" collectionFormat=\"multi\" required=\"false\""));
"<param defaultValue=\"b\" name=\"header_letter\" description=\"header param description2\" type=\"query\" collectionFormat=\"multi\" required=\"false\""));
assertTrue(xml.contains("<value>1</value>"));
assertTrue(xml.contains("<value>a</value>"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public void testFromRestModelPlaceholder() throws Exception {
assertTrue(xml.contains("</rests>"));

assertTrue(xml.contains(
"<param defaultValue=\"1\" dataType=\"integer\" name=\"header_count\" description=\"header param description1\" type=\"header\" required=\"true\""));
"<param defaultValue=\"1\" dataType=\"integer\" name=\"header_count\" description=\"header param description1\" type=\"header\""));
assertTrue(xml.contains(
"<param defaultValue=\"b\" dataType=\"string\" name=\"header_letter\" description=\"header param description2\" type=\"query\" collectionFormat=\"multi\" required=\"false\""));
"<param defaultValue=\"b\" name=\"header_letter\" description=\"header param description2\" type=\"query\" collectionFormat=\"multi\" required=\"false\""));
assertTrue(xml.contains("<value>1</value>"));
assertTrue(xml.contains("<value>a</value>"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public final class SensitiveUtils {
+ "|\\Qverificationcode\\E"
+ "|\\Qwebhookverifytoken\\E"
+ "|\\Qzookeeperpassword\\E"
// SENSITIVE-PATTERN: END
// SENSITIVE-PATTERN: END
;

private SensitiveUtils() {
Expand Down
1,843 changes: 926 additions & 917 deletions core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/camel-xml-io/src/test/resources/resequencerStream.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<route>
<from uri="direct:start" />
<resequence>
<streamConfig capacity="1000" timeout="2000"/>
<streamConfig timeout="2000"/>
<simple>in.header.seqnum</simple>
<to uri="mock:result" />
</resequence>
Expand Down
2 changes: 1 addition & 1 deletion core/camel-xml-io/src/test/resources/restAllowedValues.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<rest path="/say/bye">
<get consumes="application/json">
<param name="header_count" type="header" description="header param description1" dataType="integer"
defaultValue="1" required="true">
defaultValue="1">
<allowableValues>
<value>1</value>
<value>2</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<from uri="seda:a"/>
<pipeline>
<marshal>
<json library="Jackson"/>
<json/>
</marshal>
<to uri="seda:b"/>
</pipeline>
Expand Down
2 changes: 1 addition & 1 deletion core/camel-xml-io/src/test/resources/routingSlip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<routes id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="seda:a"/>
<routingSlip uriDelimiter=",">
<routingSlip>
<header>destinations</header>
</routingSlip>
</route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<routes id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="seda:a"/>
<routingSlip uriDelimiter=",">
<routingSlip>
<header>theRoutingSlipHeader</header>
</routingSlip>
</route>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Renamed `ExchangePropertyKey.ACTIVE_SPAN` to `ExchangePropertyKey.OTEL_ACTIVE_SP
The `queueSize` attribute on endpoints which are `ManagedBrowseableEndpoint` is changed from returning a `Long` value
to an `Integer` value.

=== camel-xml-io

The XML dumper no longer includes attributes which are using default values.

=== camel-jackson

The option `useWriter` on JSON data format and camel-jackson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.apache.camel.maven.packaging.generics.JandexStore;
import org.apache.camel.spi.Metadata;
import org.apache.camel.tooling.util.srcgen.GenericType;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -515,5 +516,25 @@ public String getAttributeName() {
return an;
}

public String getDefaultValue() {
String answer = null;
Metadata m = getAnnotation(Metadata.class);
if (m != null) {
answer = m.defaultValue();
}
if (answer == null || answer.isBlank()) {
answer = "null";
} else {
if (answer.equals("\"")) {
answer = "\\\"";
}
if (answer.equals("\\")) {
answer = "\\\\";
}
answer = "\"" + answer + "\"";
}
return answer;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public class ModelWriter extends BaseWriter {
#end
#foreach( $member in $thisAttributes )
#if( $member.type.getName() == "java.lang.String" )
doWriteAttribute("${member.attributeName}", def.${member.getter}());
doWriteAttribute("${member.attributeName}", def.${member.getter}(), ${member.defaultValue});
#else
doWriteAttribute("${member.attributeName}", toString(def.${member.getter}()));
doWriteAttribute("${member.attributeName}", toString(def.${member.getter}()), ${member.defaultValue});
#end
#end
#end
Expand Down Expand Up @@ -277,10 +277,19 @@ public class ModelWriter extends BaseWriter {

protected void doWriteAttribute(
String attribute,
Object value)
String value)
throws IOException {
doWriteAttribute(attribute, value, null);
}
protected void doWriteAttribute(
String attribute,
String value,
String defaultValue)
throws IOException {
if (value != null) {
attribute(attribute, value);
if (defaultValue == null || !defaultValue.equals(value)) {
attribute(attribute, value);
}
}
}
protected void doWriteValue(String value) throws IOException {
Expand Down