From a464ebbe4d7b061e393d9939bef1eb371719a2d4 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Mon, 21 Jan 2019 11:13:06 -0500 Subject: [PATCH] [fix] Conjure Enum values support numeric characters --- .../java/com/palantir/product/SimpleEnum.java | 10 ++++++++++ .../palantir/conjure/java/types/WireFormatTests.java | 1 + conjure-java-core/src/test/resources/ete-service.yml | 1 + conjure-java-core/src/test/resources/example-types.yml | 1 + .../conjure/java/lib/internal/ConjureEnums.java | 2 +- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/SimpleEnum.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/SimpleEnum.java index 304bbc56d..2fdb73487 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/SimpleEnum.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/SimpleEnum.java @@ -21,6 +21,8 @@ public final class SimpleEnum { public static final SimpleEnum VALUE = new SimpleEnum(Value.VALUE, "VALUE"); + public static final SimpleEnum VALUE2 = new SimpleEnum(Value.VALUE2, "VALUE2"); + private final Value value; private final String string; @@ -57,6 +59,8 @@ public static SimpleEnum valueOf(String value) { switch (value) { case "VALUE": return VALUE; + case "VALUE2": + return VALUE2; default: ConjureEnums.validate(value); return new SimpleEnum(Value.UNKNOWN, value); @@ -67,6 +71,8 @@ public T accept(Visitor visitor) { switch (value) { case VALUE: return visitor.visitValue(); + case VALUE2: + return visitor.visitValue2(); default: return visitor.visitUnknown(string); } @@ -76,6 +82,8 @@ public T accept(Visitor visitor) { public enum Value { VALUE, + VALUE2, + UNKNOWN } @@ -83,6 +91,8 @@ public enum Value { public interface Visitor { T visitValue(); + T visitValue2(); + T visitUnknown(String unknownValue); } } diff --git a/conjure-java-core/src/test/java/com/palantir/conjure/java/types/WireFormatTests.java b/conjure-java-core/src/test/java/com/palantir/conjure/java/types/WireFormatTests.java index f4ea5404e..2802a5bbc 100644 --- a/conjure-java-core/src/test/java/com/palantir/conjure/java/types/WireFormatTests.java +++ b/conjure-java-core/src/test/java/com/palantir/conjure/java/types/WireFormatTests.java @@ -174,6 +174,7 @@ public void testEnumCasingDeserializationInvariantToInputCase() throws Exception .isInstanceOf(SafeIllegalArgumentException.class) .hasLogMessage("Enum values must use UPPER_SNAKE_CASE") .hasExactlyArgs(UnsafeArg.of("value", "oNE")); + assertThat(mapper.readValue("\"100\"", EnumExample.class)).isEqualTo(EnumExample.valueOf("100")); } private LoggableExceptionAssert assertThatExceptionThrownRootCause( diff --git a/conjure-java-core/src/test/resources/ete-service.yml b/conjure-java-core/src/test/resources/ete-service.yml index a32451144..e3bf4e4da 100644 --- a/conjure-java-core/src/test/resources/ete-service.yml +++ b/conjure-java-core/src/test/resources/ete-service.yml @@ -13,6 +13,7 @@ types: SimpleEnum: values: - VALUE + - VALUE2 services: EmptyPathService: diff --git a/conjure-java-core/src/test/resources/example-types.yml b/conjure-java-core/src/test/resources/example-types.yml index b8c2fde0d..b7b635c4e 100644 --- a/conjure-java-core/src/test/resources/example-types.yml +++ b/conjure-java-core/src/test/resources/example-types.yml @@ -184,3 +184,4 @@ types: SimpleEnum: values: - VALUE + - VALUE2 diff --git a/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureEnums.java b/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureEnums.java index 84d249e05..2803c16d0 100644 --- a/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureEnums.java +++ b/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureEnums.java @@ -43,6 +43,6 @@ public static void validate(String value) { } private static boolean isAllowedCharacter(char character) { - return (character >= 'A' && character <= 'Z') || character == '_'; + return (character >= 'A' && character <= 'Z') || (character >= '0' && character <= '9') || character == '_'; } }