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

[java-gen] Fix default value encoding for enums #4677

Merged
merged 1 commit into from Dec 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@

#### Bugs
* Fix #4666: fixed okhttp calls not explicitly closing
* Fix #4677: [java-generator] Fix default encoding of enums

### 6.3.0 (2022-12-12)

Expand Down
Expand Up @@ -168,7 +168,8 @@ public GeneratorResult generateJava() {
GeneratorResult gr = prop.generateJava();

// For now the inner types are only for enums
if (!gr.getInnerClasses().isEmpty()) {
boolean isEnum = !gr.getInnerClasses().isEmpty();
if (isEnum) {
for (GeneratorResult.ClassResult enumCR : gr.getInnerClasses()) {
Optional<EnumDeclaration> ed = enumCR.getCompilationUnit().getEnumByName(enumCR.getName());
if (ed.isPresent()) {
Expand Down Expand Up @@ -244,7 +245,7 @@ public GeneratorResult generateJava() {
}

if (prop.getDefaultValue() != null) {
Expression primitiveDefault = generatePrimitiveDefaultInitializerExpression(prop);
Expression primitiveDefault = (isEnum) ? null : generatePrimitiveDefaultInitializerExpression(prop);

if (primitiveDefault != null) {
objField.getVariable(0).setInitializer(primitiveDefault);
Expand Down
Expand Up @@ -23,6 +23,7 @@

import java.util.List;

import static io.cert_manager.v1.CertificateRequestSpec.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

class TestDefaultValues {
Expand All @@ -44,6 +45,7 @@ void testDefaultValues() throws Exception {
Double eight = cr.getSpec().getEight();
List<String> nine = cr.getSpec().getNine();
Ten ten = cr.getSpec().getTen();
Eleven eleven = cr.getSpec().getEleven();

// Assert
assertEquals("one", one);
Expand All @@ -59,5 +61,6 @@ void testDefaultValues() throws Exception {
assertEquals("nine2", nine.get(1));
assertEquals("tenone", ten.getTenOne());
assertEquals("tentwo", ten.getTenTwo());
assertEquals(Eleven.BAZ, eleven);
}
}
Expand Up @@ -90,5 +90,12 @@ spec:
default:
tenOne: "tenone"
tenTwo: "tentwo"
eleven:
type: string
enum:
- "foo"
- "bar"
- "baz"
default: "baz"
served: true
storage: true