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

[crd-gen] More principled filtering of enum constants for CRD generation #5323

Merged
merged 6 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fix #5221: Empty kube config file causes NPE
* Fix #5281: Ensure the KubernetesCrudDispatcher's backing map is accessed w/lock
* Fix #5293: Ensured the mock server uses only generic or JsonNode parsing
* Fix #4225: [crd-generator] Principled generation of enum values instead of considering more properties

#### Improvements
* Fix #5166: Remove opinionated messages from Config's `errorMessages` and deprecate it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -584,7 +585,7 @@ private String extractUpdatedNameFromJacksonPropertyIfPresent(Property property)
.anyMatch(a -> a.getClassRef().getFullyQualifiedName().equals(ANNOTATION_JSON_IGNORE));

if (ignored) {
return "$" + property.getName();
return null;
} else {
return property.getAnnotations().stream()
// only consider JsonProperty annotation
Expand Down Expand Up @@ -691,10 +692,9 @@ private T internalFromImpl(String name, TypeRef typeRef, Set<String> visited, In
// check if we're dealing with an enum
if (def.isEnum()) {
final JsonNode[] enumValues = def.getProperties().stream()
.filter(property -> property.isStatic() && property.isPublic()
&& def.getFullyQualifiedName().equals(property.getTypeRef().toString()))
.filter(Property::isEnumConstant)
.map(this::extractUpdatedNameFromJacksonPropertyIfPresent)
.filter(n -> !n.startsWith("$"))
.filter(Objects::nonNull)
.map(JsonNodeFactory.instance::textNode)
.toArray(JsonNode[]::new);
return enumProperty(enumValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,21 @@ public enum AnnotatedEnum {
public String getAbbreviation() {
return abbreviation;
}

public static AnnotatedEnum SIM = es;

public AnotherEnum one = AnotherEnum.ONE;

public AnotherEnum getOne() {
return one;
}

public void setOne(AnotherEnum one) {
this.one = one;
}
}

public enum AnotherEnum {
ONE
}
}