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 92a61ec8d36..39bb27d22d6 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 @@ -325,7 +325,7 @@ private T internalFromImpl(TypeDef definition, Set visited, List visited, List fooProperties = fooField.getProperties(); + JSONSchemaProps configAsMapField = fooProperties.get("configAsMap"); + + assertNotNull(configAsMapField); + assertTrue(configAsMapField.getXKubernetesPreserveUnknownFields()); } @Test @@ -196,7 +202,7 @@ void shouldExtractPropertiesSchemaFromExtractValueAnnotation() { assertEquals(2, properties.size()); final JSONSchemaProps specSchema = properties.get("spec"); Map spec = specSchema.getProperties(); - assertEquals(2, spec.size()); + assertEquals(3, spec.size()); // check typed SchemaFrom JSONSchemaProps foo = spec.get("foo"); @@ -222,6 +228,13 @@ void shouldExtractPropertiesSchemaFromExtractValueAnnotation() { // you can exclude fields assertNull(barProps.get("baz")); + + // verify that x-kubernetes-preserve-unknown-fields isn't on parent object when + // nested object is annotated with @PreserveUnknownFields + JSONSchemaProps qux = spec.get("qux"); + Map quxProps = qux.getProperties(); + assertTrue(quxProps.get("foo").getXKubernetesPreserveUnknownFields()); + assertNull(qux.getXKubernetesPreserveUnknownFields()); } @Test