Skip to content

Commit

Permalink
chore: Fabric8NameHelper renames fields with reserved keywords
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Aug 29, 2022
1 parent c568ea4 commit 774f716
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 348 deletions.
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

This file was deleted.

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

0 comments on commit 774f716

Please sign in to comment.