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

[fix] Conjure Enum values support numeric characters #197

Merged
merged 1 commit into from
Jan 21, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -67,6 +71,8 @@ public <T> T accept(Visitor<T> visitor) {
switch (value) {
case VALUE:
return visitor.visitValue();
case VALUE2:
return visitor.visitValue2();
default:
return visitor.visitUnknown(string);
}
Expand All @@ -76,13 +82,17 @@ public <T> T accept(Visitor<T> visitor) {
public enum Value {
VALUE,

VALUE2,

UNKNOWN
}

@Generated("com.palantir.conjure.java.types.EnumGenerator")
public interface Visitor<T> {
T visitValue();

T visitValue2();

T visitUnknown(String unknownValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends Throwable & SafeLoggable> LoggableExceptionAssert<T> assertThatExceptionThrownRootCause(
Expand Down
1 change: 1 addition & 0 deletions conjure-java-core/src/test/resources/ete-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ types:
SimpleEnum:
values:
- VALUE
- VALUE2

services:
EmptyPathService:
Expand Down
1 change: 1 addition & 0 deletions conjure-java-core/src/test/resources/example-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,4 @@ types:
SimpleEnum:
values:
- VALUE
- VALUE2
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '_';
}
}