Skip to content

Commit

Permalink
[java-generator] Avoid to emit Java Keywords as package names
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP authored and manusa committed Aug 12, 2023
1 parent 07ddb89 commit d969f01
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Bugs
* Fix #5382: [java-generator] Allow to deserialize more valid RFC3339 date-time and make the format customizable
* Fix #5380: [java-generator] Avoid to emit Java Keywords as package names

#### Improvements
* Fix #5368: added support for additional ListOptions fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public static String packageName(String str) {
if (pkg.equals(str)) { // avoid package/class name clash
pkg = "_" + pkg;
}
// https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html
// if the package name contains a reserved Java keyword ... the suggested convention is to add an underscore
if (JAVA_KEYWORDS.contains(pkg)) {
pkg = pkg + "_";
}
return pkg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.example.v1.Dummy;
import com.example.v1.DummySpec;
import com.example.v1.dummyspec.Package;
import com.example.v1.dummyspec.package_.Foo;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.client.utils.Serialization;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -48,6 +50,7 @@ void testDeserialization() {
assertEquals("3", spec.getThree_quote());
assertEquals("4", spec.getFour_doublequote());
assertEquals("5", spec.getFive_slash());
assertEquals("6", spec.get_package().getFoo().getBar());
}

@Test
Expand All @@ -63,6 +66,11 @@ void testAgainstSample() throws Exception {
spec.setThree_quote("3");
spec.setFour_doublequote("4");
spec.setFive_slash("5");
Foo foo = new Foo();
foo.setBar("6");
Package pack = new Package();
pack.setFoo(foo);
spec.set_package(pack);
sample.setSpec(spec);
ObjectMeta om = new ObjectMeta();
om.setName("sample");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ spec:
type: string
five/slash:
type: string
package:
type: object
properties:
foo:
type: object
properties:
bar:
type: string
scope: Namespaced
names:
plural: dummies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ spec:
three'quote: "3"
four"doublequote: "4"
five/slash: "5"
package:
foo:
bar: "6"

0 comments on commit d969f01

Please sign in to comment.