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

chore: Fabric8NameHelper renames fields with reserved keywords #4358

Merged
merged 1 commit into from
Aug 29, 2022
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
3 changes: 0 additions & 3 deletions extensions/certmanager/model-v1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
<configuration>
<target>
<echo>removing the duplicate generated class</echo>
<delete
file="${generate.targetDirectory}/io/fabric8/certmanager/api/model/acme/v1/ACMEChallengeSolverHTTP01Ingress.java"
verbose="true" />
<delete
file="${generate.targetDirectory}/io/fabric8/certmanager/api/model/v1/CertificateRequestSpec.java"
verbose="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@

package io.fabric8.certmanager.api.model.acme.v1;

import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerPort;
import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.KubernetesResource;
import io.fabric8.kubernetes.api.model.LabelSelector;
import io.fabric8.kubernetes.api.model.LocalObjectReference;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.ObjectReference;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.PodTemplateSpec;
import io.fabric8.kubernetes.api.model.ResourceRequirements;
import io.fabric8.kubernetes.api.model.Volume;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.sundr.builder.annotations.Buildable;
import io.sundr.builder.annotations.BuildableReference;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

@JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"apiVersion",
"kind",
"metadata",
"class",
"ingressTemplate",
"name",
"podTemplate",
"serviceType"
})
@ToString
@EqualsAndHashCode
@Setter
@Accessors(prefix = {
"_",
""
})
@Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = {
@BuildableReference(ObjectMeta.class),
@BuildableReference(LabelSelector.class),
@BuildableReference(Container.class),
@BuildableReference(PodTemplateSpec.class),
@BuildableReference(ResourceRequirements.class),
@BuildableReference(IntOrString.class),
@BuildableReference(ObjectReference.class),
@BuildableReference(LocalObjectReference.class),
@BuildableReference(PersistentVolumeClaim.class),
@BuildableReference(EnvVar.class),
@BuildableReference(ContainerPort.class),
@BuildableReference(Volume.class),
@BuildableReference(VolumeMount.class)
})
public class ACMEChallengeSolverHTTP01Ingress implements KubernetesResource
{

@JsonProperty("class")
private String className;
@JsonProperty("ingressTemplate")
private ACMEChallengeSolverHTTP01IngressTemplate ingressTemplate;
@JsonProperty("name")
private java.lang.String name;
@JsonProperty("podTemplate")
private ACMEChallengeSolverHTTP01IngressPodTemplate podTemplate;
@JsonProperty("serviceType")
private java.lang.String serviceType;
@JsonIgnore
private Map<java.lang.String, Object> additionalProperties = new HashMap<java.lang.String, Object>();

/**
* No args constructor for use in serialization
*
*/
public ACMEChallengeSolverHTTP01Ingress() {
}

/**
*
* @param serviceType
* @param ingressTemplate
* @param name
* @param podTemplate
* @param className
*/
public ACMEChallengeSolverHTTP01Ingress(String className, ACMEChallengeSolverHTTP01IngressTemplate ingressTemplate, java.lang.String name, ACMEChallengeSolverHTTP01IngressPodTemplate podTemplate, java.lang.String serviceType) {
super();
this.className = className;
this.ingressTemplate = ingressTemplate;
this.name = name;
this.podTemplate = podTemplate;
this.serviceType = serviceType;
}

@JsonProperty("class")
public String getClassName() {
return className;
}

@JsonProperty("class")
public void setClassName(String className) {
this.className = className;
}

@JsonProperty("ingressTemplate")
public ACMEChallengeSolverHTTP01IngressTemplate getIngressTemplate() {
return ingressTemplate;
}

@JsonProperty("ingressTemplate")
public void setIngressTemplate(ACMEChallengeSolverHTTP01IngressTemplate ingressTemplate) {
this.ingressTemplate = ingressTemplate;
}

@JsonProperty("name")
public java.lang.String getName() {
return name;
}

@JsonProperty("name")
public void setName(java.lang.String name) {
this.name = name;
}

@JsonProperty("podTemplate")
public ACMEChallengeSolverHTTP01IngressPodTemplate getPodTemplate() {
return podTemplate;
}

@JsonProperty("podTemplate")
public void setPodTemplate(ACMEChallengeSolverHTTP01IngressPodTemplate podTemplate) {
this.podTemplate = podTemplate;
}

@JsonProperty("serviceType")
public java.lang.String getServiceType() {
return serviceType;
}

@JsonProperty("serviceType")
public void setServiceType(java.lang.String serviceType) {
this.serviceType = serviceType;
}

@JsonAnyGetter
public Map<java.lang.String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(java.lang.String name, Object value) {
this.additionalProperties.put(name, value);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,38 @@
import org.jsonschema2pojo.GenerationConfig;
import org.jsonschema2pojo.util.NameHelper;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Renames reserved fields name to predefined values (PROTECTED_WORD_MAP)
* <p>
* Overrides default provided NameHelper to overcome getter/setter naming convention mismatch between Sundr.io
* and jsonschema2pojo.
*
* <p>
* There are issues with properties such as x-kubernetes-foo or xKubernetesFoo, sundrio expects a getter as
* getXKubernetesFoo while jsonschema2pojo produces getxKubernetesFoo.
*/
public class Fabric8NameHelper extends NameHelper {

private static final Map<String, String> PROTECTED_WORD_MAP = new HashMap<>();
static {
PROTECTED_WORD_MAP.put("class", "className");
}
private static final Pattern SINGLE_LETTER_PREFIX_WORD_PROPERTY = Pattern.compile("^[a-z]((-[a-zA-Z])|[A-Z])(.*)$");

public Fabric8NameHelper(GenerationConfig generationConfig) {
super(generationConfig);
}

@Override
public String getFieldName(String propertyName, JsonNode node) {
final String fieldName = super.getFieldName(propertyName, node);
return PROTECTED_WORD_MAP.getOrDefault(fieldName, fieldName);
}

@Override
public String getGetterName(String propertyName, JType type, JsonNode node) {
return correctCamelCaseWithPrefix(propertyName, super.getGetterName(propertyName, type, node));
Expand Down
Loading