Skip to content

Commit

Permalink
fix: crd-gen includes only enum values and discard enum fields (#4230)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrea Leo <[email protected]>
  • Loading branch information
leoandrea7 and Andrea Leo authored Jun 13, 2023
1 parent 6997cc2 commit e5d7f64
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#### Bugs
* Fix #5218: No export for `io.fabric8.tekton.triggers.internal.knative.pkg.apis.duck.v1beta1` in tekton v1beta1 triggers model
* Fix #5224: Ensuring jetty sets the User-Agent header
* Fix #4225: Enum fields written in generated crd yaml

#### Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,29 @@
import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.Quantity;
import io.sundr.builder.internal.functions.TypeAs;
import io.sundr.model.*;
import io.sundr.model.AnnotationRef;
import io.sundr.model.ClassRef;
import io.sundr.model.Method;
import io.sundr.model.PrimitiveRefBuilder;
import io.sundr.model.Property;
import io.sundr.model.TypeDef;
import io.sundr.model.TypeRef;
import io.sundr.utils.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static io.sundr.model.utils.Types.BOOLEAN_REF;
import static io.sundr.model.utils.Types.DOUBLE_REF;
Expand Down Expand Up @@ -664,6 +681,8 @@ 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()))
.map(this::extractUpdatedNameFromJacksonPropertyIfPresent)
.filter(n -> !n.startsWith("$"))
.map(JsonNodeFactory.instance::textNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,20 @@ public void setEmptySetter2(boolean emptySetter2) {
}

public enum AnnotatedEnum {
non,
non("N"),
@JsonProperty("oui")
Yes,
es("O"),
@JsonIgnore
Maybe
Maybe("Maybe");

private final String abbreviation;

AnnotatedEnum(String abbreviation) {
this.abbreviation = abbreviation;
}

public String getAbbreviation() {
return abbreviation;
}
}
}

0 comments on commit e5d7f64

Please sign in to comment.