kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

Support use of @JsonValue on enums for CRD generation

Open bbende opened this issue 1 year ago • 6 comments

Is your enhancement related to a problem? Please describe

I have a Java enum that is generated from an Open API spec, and the generated enum uses @JsonValue on a getter to indicate the value to use for serialization. It also generates a static fromValue method with @JsonCreator.

Example:

@JsonValue
public String getValue() {
    return this.value;
}

public String toString() {
    return String.valueOf(this.value);
}

    @JsonCreator
    public static MyEnum fromValue(String value) {
        MyEnum[] var1 = values();
        int var2 = var1.length;

        for(int var3 = 0; var3 < var2; ++var3) {
            MyEnum b = var1[var3];
            if (b.value.equals(value)) {
                return b;
            }
        }

        throw new IllegalArgumentException("Unexpected value '" + value + "'");
    }

I want to use this field in a custom resource that generates the CRD from the Java classes, but the generated CRD is not using the values from the method with @JsonValue, so the enum items have all the values from the name() method like VALUE_A , VALUE_B.

I assume this is because this code here only looks for @JsonProperty:

https://github.com/fabric8io/kubernetes-client/blob/main/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java#L114

Describe the solution you'd like

I would like to see if it is possible to also consider @JsonValue in the code linked above that processes enumerations and looks for an alternate value to use for the enum value.

Describe alternatives you've considered

No response

Additional context

No response

bbende avatar Oct 11 '24 17:10 bbende