forked from fabric8io/kubernetes-client
-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix property case-handling during CRD gen #194
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -517,7 +517,7 @@ public void process() { | |
break; | ||
case ANNOTATION_JSON_PROPERTY: | ||
final String nameFromAnnotation = (String) a.getParameters().get(VALUE); | ||
if (!Strings.isNullOrEmpty(nameFromAnnotation) && !propertyName.equals(nameFromAnnotation)) { | ||
if (!Strings.isNullOrEmpty(nameFromAnnotation)) { | ||
renamedTo = nameFromAnnotation; | ||
} | ||
break; | ||
|
@@ -711,12 +711,38 @@ public Property process() { | |
} | ||
}); | ||
|
||
String caseCorrectedPropertyName = getCaseCorrectedPropertyName(); | ||
if(renamedTo == null && !original.getName().equals(caseCorrectedPropertyName) ) { | ||
renamedTo = caseCorrectedPropertyName; | ||
} | ||
|
||
TypeRef typeRef = schemaFrom != null ? schemaFrom : parameterMap.exchange(original.getTypeRef()); | ||
String finalName = renamedTo != null ? renamedTo : original.getName(); | ||
|
||
return new Property(original.getAnnotations(), typeRef, finalName, | ||
original.getComments(), false, false, original.getModifiers(), original.getAttributes()); | ||
} | ||
|
||
private String getCaseCorrectedPropertyName() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment here describing what "case correction" in this case means? |
||
String capitalizedOriginalPropertyName = original.getNameCapitalized(); | ||
StringBuilder newPropertyNameBuilder = new StringBuilder(); | ||
|
||
int index; | ||
for (index = 0;index<capitalizedOriginalPropertyName.length();index++) { | ||
char charAtIndex = capitalizedOriginalPropertyName.charAt(index); | ||
if(Character.isUpperCase(charAtIndex)) { | ||
newPropertyNameBuilder.append(Character.toLowerCase(charAtIndex)); | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
if(index<capitalizedOriginalPropertyName.length()) { | ||
newPropertyNameBuilder.append(capitalizedOriginalPropertyName.substring(index)); | ||
} | ||
|
||
return newPropertyNameBuilder.toString(); | ||
} | ||
} | ||
|
||
/** | ||
|
12 changes: 12 additions & 0 deletions
12
...api/src/test/java/io/fabric8/crd/example/serialization/AnnotatedSerializationExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.fabric8.crd.example.serialization; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class AnnotatedSerializationExample { | ||
String fOoBar; | ||
|
||
@JsonProperty("fOoBar") | ||
public String getFOoBar() { | ||
return fOoBar; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...enerator/api/src/test/java/io/fabric8/crd/example/serialization/SerializationExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.fabric8.crd.example.serialization; | ||
|
||
public class SerializationExample { | ||
String uRL; | ||
String fOoBar; | ||
String normalCase; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test my understanding - this change is necessary because we want the
nameFromAnnotation
to override anything we might do fromgetCaseCorrectedPropertyName()
? Since ifrenamedTo
is notnull
, the result ofgetCaseCorrectedPropertyName()
is unused.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. If someone actually wanted
getHBaseImage()
to generate a CRD field ofhBaseImage
instead ofhbaseImage
, then they should useJsonProperty
to annotate that getter to override our default conversion, but if the internal field name was alreadyhBaseImage
(because maybe the field is generated with Immutables) then without this line setting that wouldn't be detected as an override and we'd use the new convention anyway.