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-generator] Fix encoding for empty strings in enums #4769

Merged
merged 1 commit into from
Jan 16, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Fix #4574: fromServer has been deprecated - it no longer needs to be called. All get() operations will fetch the resource(s) from the api server. If you need the context item that was passed in from a resource, load, or resourceList methods, use the item or items method.
* Fix #4633: client.run().withRunConfig was deprecated. Use withNewRunConfig instead.
* Fix #4663: Config.maxConcurrentRequests and Config.maxConcurrentRequestsPerHost will no longer be used. Instead they will default to unlimited for all clients. Due to the ability of the fabric8 client to start long running requests (either websocket or regular http) and how this is treated by the underlying clients you can easily exhaust these values and enter a state where the client is unresponsive without any additional information on what is occurring.
* Fix #4769: [java-generator] Fix encoding of empty strings as valid enums

### 6.3.1 (2022-12-15)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.body.*;
import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.stmt.ReturnStmt;
import io.fabric8.java.generator.Config;

import java.util.ArrayList;
Expand Down Expand Up @@ -56,7 +58,11 @@ private String sanitizeEnumEntry(final String str) {
if (config.isUppercaseEnums()) {
ret = ret.toUpperCase(Locale.ROOT);
}
return ret.replaceAll("[\\s/]", "_");
if (ret.isEmpty()) {
return "_EMPTY";
} else {
return ret.replaceAll("[\\s/]", "_");
}
}

@Override
Expand All @@ -77,6 +83,13 @@ public GeneratorResult generateJava() {
new NameExpr(VALUE),
AssignExpr.Operator.ASSIGN)));

MethodDeclaration getValue = en
.addMethod("getValue", Modifier.Keyword.PUBLIC);
getValue.setType(JAVA_LANG_STRING);
getValue
.setBody(new BlockStmt().addStatement(new ReturnStmt(VALUE)));
getValue.addAnnotation("com.fasterxml.jackson.annotation.JsonValue");

for (String k : this.values) {
String constantName;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class JokeRequestSpec implements io.fabric8.kubernetes.api.model.Kubernet
Category(java.lang.String value) {
this.value = value;
}

@com.fasterxml.jackson.annotation.JsonValue()
public java.lang.String getValue() {
return value;
}
}

@com.fasterxml.jackson.annotation.JsonProperty("category")
Expand Down Expand Up @@ -72,6 +77,11 @@ public class JokeRequestSpec implements io.fabric8.kubernetes.api.model.Kubernet
Excluded(java.lang.String value) {
this.value = value;
}

@com.fasterxml.jackson.annotation.JsonValue()
public java.lang.String getValue() {
return value;
}
}

@com.fasterxml.jackson.annotation.JsonProperty("excluded")
Expand Down Expand Up @@ -145,6 +155,11 @@ public class JokeRequestStatus implements io.fabric8.kubernetes.api.model.Kubern
State(java.lang.String value) {
this.value = value;
}

@com.fasterxml.jackson.annotation.JsonValue()
public java.lang.String getValue() {
return value;
}
}

@com.fasterxml.jackson.annotation.JsonProperty("state")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ void testDeserialization() {
List<CertificateRequestSpec.Usages> usagesList = sample.getSpec().getUsages();

// Assert
assertEquals(4, usagesList.size());
assertEquals(CertificateRequestSpec.Usages.SIGNING, usagesList.get(0));
assertEquals(CertificateRequestSpec.Usages.DIGITAL_SIGNATURE, usagesList.get(1));
assertEquals(CertificateRequestSpec.Usages.SERVER_AUTH, usagesList.get(2));
assertEquals(CertificateRequestSpec.Usages.S_MIME, usagesList.get(3));
assertEquals(5, usagesList.size());
assertEquals(CertificateRequestSpec.Usages._EMPTY, usagesList.get(0));
assertEquals(CertificateRequestSpec.Usages.SIGNING, usagesList.get(1));
assertEquals(CertificateRequestSpec.Usages.DIGITAL_SIGNATURE, usagesList.get(2));
assertEquals(CertificateRequestSpec.Usages.SERVER_AUTH, usagesList.get(3));
assertEquals(CertificateRequestSpec.Usages.S_MIME, usagesList.get(4));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ spec:
description: 'KeyUsage specifies valid usage contexts for keys. See: https://tools.ietf.org/html/rfc5280#section-4.2.1.3 https://tools.ietf.org/html/rfc5280#section-4.2.1.12 Valid KeyUsage values are as follows: "signing", "digital signature", "content commitment", "key encipherment", "key agreement", "data encipherment", "cert sign", "crl sign", "encipher only", "decipher only", "any", "server auth", "client auth", "code signing", "email protection", "s/mime", "ipsec end system", "ipsec tunnel", "ipsec user", "timestamping", "ocsp signing", "microsoft sgc", "netscape sgc"'
type: string
enum:
- ""
- signing
- digital signature
- content commitment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ kind: CertificateRequest
metadata:
name: my-ca-cr
spec:
request: LS0tL
request: dGVzdAo=
isCA: false
usages:
- ""
- signing
- digital signature
- server auth
Expand Down