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

fix x-kubernetes-preserve-unknown-fields mistakenly added to parent object #134

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private T internalFromImpl(TypeDef definition, Set<String> visited, List<Interna
continue;
}
final T schema = internalFromImpl(name, possiblyRenamedProperty.getTypeRef(), visited, schemaSwaps, parameterMap);
if (facade.preserveUnknownFields) {
if (facade.isJsonAny) {
preserveUnknownFields = true;
}

Expand Down Expand Up @@ -416,6 +416,7 @@ private static class PropertyOrAccessor {
private boolean nullable;
private boolean required;
private boolean ignored;
private boolean isJsonAny;
private boolean preserveUnknownFields;
private String description;
private TypeRef schemaFrom;
Expand Down Expand Up @@ -478,6 +479,8 @@ public void process() {
break;
case ANNOTATION_JSON_ANY_GETTER:
case ANNOTATION_JSON_ANY_SETTER:
isJsonAny = true;
break;
case ANNOTATION_PERSERVE_UNKNOWN_FIELDS:
preserveUnknownFields = true;
break;
Expand Down Expand Up @@ -520,6 +523,10 @@ public boolean isIgnored() {
return ignored;
}

public boolean isJsonAny() {
return isJsonAny;
}

public boolean isPreserveUnknownFields() {
return preserveUnknownFields;
}
Expand Down Expand Up @@ -564,6 +571,7 @@ private static class PropertyFacade {
private boolean nullable;
private boolean required;
private boolean ignored;
private boolean isJsonAny;
private boolean preserveUnknownFields;
private final Property original;
private String nameContributedBy;
Expand Down Expand Up @@ -644,6 +652,7 @@ public Property process() {
ignored = true;
}

isJsonAny = p.isJsonAny() || isJsonAny;
preserveUnknownFields = p.isPreserveUnknownFields() || preserveUnknownFields;

if (p.contributeSchemaFrom()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public class ExtractionSpec {
@PreserveUnknownFields
private Foo bar;

private Qux qux;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.fabric8.crd.example.extraction;

import io.fabric8.crd.generator.annotation.PreserveUnknownFields;

public class Qux {
@PreserveUnknownFields
public Foo foo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void shouldExtractPropertiesSchemaFromExtractValueAnnotation() {
assertEquals(2, properties.size());
final JSONSchemaProps specSchema = properties.get("spec");
Map<String, JSONSchemaProps> spec = specSchema.getProperties();
assertEquals(2, spec.size());
assertEquals(3, spec.size());

// check typed SchemaFrom
JSONSchemaProps foo = spec.get("foo");
Expand All @@ -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<String, JSONSchemaProps> quxProps = qux.getProperties();
assertTrue(quxProps.get("foo").getXKubernetesPreserveUnknownFields());
assertNull(qux.getXKubernetesPreserveUnknownFields());
}

@Test
Expand Down
Loading