diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc06220c32a..267ece8e1a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
### 6.10-SNAPSHOT
#### Bugs
+* Fix #5501: [crd-generator] Fix fallback value of `Default` annotation in presence of multiple accessors
#### Improvements
diff --git a/crd-generator/api/pom.xml b/crd-generator/api/pom.xml
index 27a26c1a8b0..8a6174432fc 100644
--- a/crd-generator/api/pom.xml
+++ b/crd-generator/api/pom.xml
@@ -82,6 +82,11 @@
validation-api
test
+
+ org.projectlombok
+ lombok
+ test
+
diff --git a/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java b/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java
index 4704ef274cd..92227db7c99 100644
--- a/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java
+++ b/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java
@@ -558,7 +558,7 @@ public Property process() {
LOGGER.debug("Description for property {} has already been contributed by: {}", name, descriptionContributedBy);
}
}
- defaultValue = p.getDefault().orElse(null);
+ defaultValue = p.getDefault().orElse(defaultValue);
min = p.getMin().orElse(min);
max = p.getMax().orElse(max);
pattern = p.getPattern().orElse(pattern);
diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/example/annotated/AnnotatedSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/example/annotated/AnnotatedSpec.java
index 895ea5d09b7..d8c602cb69d 100644
--- a/crd-generator/api/src/test/java/io/fabric8/crd/example/annotated/AnnotatedSpec.java
+++ b/crd-generator/api/src/test/java/io/fabric8/crd/example/annotated/AnnotatedSpec.java
@@ -24,7 +24,9 @@
import io.fabric8.generator.annotation.Nullable;
import io.fabric8.generator.annotation.Pattern;
import io.fabric8.generator.annotation.Required;
+import lombok.Data;
+@Data
public class AnnotatedSpec {
@JsonProperty("from-field")
@JsonPropertyDescription("from-field-description")
@@ -37,6 +39,8 @@ public class AnnotatedSpec {
private String singleDigit;
private String nullable;
private String defaultValue;
+ @Default("my-value2")
+ private String defaultValue2;
@Required
private boolean emptySetter;
@Required
diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/v1/JsonSchemaTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/v1/JsonSchemaTest.java
index f7906b2795c..a8bb31f1dad 100644
--- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/v1/JsonSchemaTest.java
+++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/v1/JsonSchemaTest.java
@@ -102,7 +102,7 @@ void shouldAugmentPropertiesSchemaFromAnnotations() throws JsonProcessingExcepti
assertNotNull(schema);
Map properties = assertSchemaHasNumberOfProperties(schema, 2);
final JSONSchemaProps specSchema = properties.get("spec");
- Map spec = assertSchemaHasNumberOfProperties(specSchema, 12);
+ Map spec = assertSchemaHasNumberOfProperties(specSchema, 13);
// check descriptions are present
assertTrue(spec.containsKey("from-field"));
@@ -154,6 +154,13 @@ void shouldAugmentPropertiesSchemaFromAnnotations() throws JsonProcessingExcepti
assertNull(defaultValue.getMaximum());
assertNull(defaultValue.getPattern());
+ final JSONSchemaProps defaultValue2 = spec.get("defaultValue2");
+ assertEquals("my-value2", YAML_MAPPER.writeValueAsString(defaultValue2.getDefault()).trim());
+ assertNull(defaultValue2.getNullable());
+ assertNull(defaultValue2.getMinimum());
+ assertNull(defaultValue2.getMaximum());
+ assertNull(defaultValue2.getPattern());
+
// check required list, should register properties with their modified name if needed
final List required = specSchema.getRequired();
assertEquals(3, required.size());
diff --git a/crd-generator/test/pom.xml b/crd-generator/test/pom.xml
index 9623b262b92..f865a182b46 100644
--- a/crd-generator/test/pom.xml
+++ b/crd-generator/test/pom.xml
@@ -38,6 +38,12 @@
io.fabric8
crd-generator-apt
+
+
+ org.projectlombok
+ lombok
+ test
+
org.junit.jupiter
diff --git a/crd-generator/test/src/test/java/io/fabric8/crd/generator/zookeeper/ZookeeperCustomResourceTest.java b/crd-generator/test/src/test/java/io/fabric8/crd/generator/zookeeper/ZookeeperCustomResourceTest.java
index f31d9e50d97..3b6190f970b 100644
--- a/crd-generator/test/src/test/java/io/fabric8/crd/generator/zookeeper/ZookeeperCustomResourceTest.java
+++ b/crd-generator/test/src/test/java/io/fabric8/crd/generator/zookeeper/ZookeeperCustomResourceTest.java
@@ -66,6 +66,7 @@ void testCrdv1beta1() {
assertEquals(1, v.getAdditionalPrinterColumns().get(0).getPriority());
assertEquals("UPTIME", v.getAdditionalPrinterColumns().get(1).getName());
assertEquals(0, v.getAdditionalPrinterColumns().get(1).getPriority());
+ assertEquals("false", props.getProperties().get("ephemeral").getDefault().asText());
});
Optional v1alpha1 = d.getSpec().getVersions().stream()
diff --git a/crd-generator/test/src/test/java/io/fabric8/crd/generator/zookeeper/v1/ZookeeperSpec.java b/crd-generator/test/src/test/java/io/fabric8/crd/generator/zookeeper/v1/ZookeeperSpec.java
index 7675e05651d..ab00d847462 100644
--- a/crd-generator/test/src/test/java/io/fabric8/crd/generator/zookeeper/v1/ZookeeperSpec.java
+++ b/crd-generator/test/src/test/java/io/fabric8/crd/generator/zookeeper/v1/ZookeeperSpec.java
@@ -15,14 +15,18 @@
*/
package io.fabric8.crd.generator.zookeeper.v1;
+import io.fabric8.generator.annotation.Default;
import io.fabric8.generator.annotation.Required;
import io.fabric8.kubernetes.model.annotation.SpecReplicas;
+import lombok.Data;
+@Data
public class ZookeeperSpec {
@SpecReplicas
private int size;
@Required
private String version;
+ @Default("false")
private boolean ephemeral;
}