From b434dd6f273d80310e009cb1d3ea7880b70ccc3f Mon Sep 17 00:00:00 2001 From: Ethan Uberseder Date: Mon, 29 Apr 2024 13:50:58 -0400 Subject: [PATCH] fix x-kubernetes-preserve-unknown-fields mistakenly added to parent object --- .../io/fabric8/crd/generator/AbstractJsonSchema.java | 11 ++++++++++- .../crd/example/extraction/ExtractionSpec.java | 2 ++ .../java/io/fabric8/crd/example/extraction/Qux.java | 8 ++++++++ .../io/fabric8/crd/generator/v1/JsonSchemaTest.java | 9 ++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/example/extraction/Qux.java 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..8a00b7db6d0 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 spec = specSchema.getProperties(); - assertEquals(2, spec.size()); + assertEquals(3, spec.size()); // check typed SchemaFrom JSONSchemaProps foo = spec.get("foo"); @@ -222,6 +222,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