-
Notifications
You must be signed in to change notification settings - Fork 43
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
Enum values are case sensitive, values are validated #143
Enum values are case sensitive, values are validated #143
Conversation
@@ -152,11 +152,11 @@ public void testEmptyObjectsDeserialize() throws Exception { | |||
} | |||
|
|||
@Test | |||
public void testEnumCasingDeserializationInvariantToInputCase() throws Exception { | |||
public void testEnumCasingDeserialization() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there no corresponding test in conjure-verifier? (I think there should be)
I think it'd be preferable to finish the discussion on #134 prior to merging this. As noted, this might be a significant break since early adopters requested this leniency during decoding. |
ack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spec discussion ongoing in palantir/conjure#193
assertThat(mapper.readValue("\"ONE\"", EnumExample.class)).isEqualTo(EnumExample.ONE); | ||
assertThat(mapper.readValue("\"one\"", EnumExample.class)).isEqualTo(EnumExample.ONE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a pretty dangerous behaviour change in the case where users might have already persisted lowercase enum values to a database. Would prefer this to throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, I will add validation matching our schema regex to the valueOf(String) statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I'll just validate chars A-Z_
without dealing with leading/trailing/duplicate underscores, we can add that later.
cc534b7
to
14488b0
Compare
1309385
to
7327148
Compare
7327148
to
1ac4319
Compare
The Conjure specification requires upper case string values for enum constants.
1ac4319
to
5276c58
Compare
.hasExactlyArgs(UnsafeArg.of("value", "onE")); | ||
assertThatExceptionThrownRootCause(() -> mapper.readValue("\"oNE\"", EnumExample.class)) | ||
.isInstanceOf(SafeIllegalArgumentException.class) | ||
.hasLogMessage("Enum values must use SCREAMING_SNAKE_CASE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we tweak this error message to just say UPPER_SNAKE_CASE
? I think the 'screaming' bit might be a bit more humour than java programmers can handle.
Edit I'm just gonna push this fix and merge I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks Dan!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah whoops, can I have some perms?
This reverts commit 4d39bdd.
The Conjure specification requires upper case string values for
enum constants.