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

Enum values are case sensitive, values are validated #143

Merged

Conversation

carterkozak
Copy link
Contributor

The Conjure specification requires upper case string values for
enum constants.

@carterkozak carterkozak requested a review from a team as a code owner December 25, 2018 13:09
@@ -152,11 +152,11 @@ public void testEmptyObjectsDeserialize() throws Exception {
}

@Test
public void testEnumCasingDeserializationInvariantToInputCase() throws Exception {
public void testEnumCasingDeserialization() throws Exception {
Copy link
Contributor

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)

@markelliot
Copy link
Contributor

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.

@carterkozak
Copy link
Contributor Author

ack

Copy link
Contributor

@iamdanfox iamdanfox left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@carterkozak carterkozak force-pushed the ckozak/case_sensitive_enums branch 2 times, most recently from cc534b7 to 14488b0 Compare January 10, 2019 18:02
@carterkozak carterkozak changed the title Enum.valueOf no longer invokes toUpperCase on inputs Enum values are case sensitive, unknown values are validated Jan 10, 2019
@carterkozak carterkozak force-pushed the ckozak/case_sensitive_enums branch from 1309385 to 7327148 Compare January 10, 2019 18:33
@carterkozak carterkozak changed the title Enum values are case sensitive, unknown values are validated Enum values are case sensitive, values are validated Jan 10, 2019
@carterkozak carterkozak force-pushed the ckozak/case_sensitive_enums branch from 7327148 to 1ac4319 Compare January 10, 2019 19:09
The Conjure specification requires upper case string values for
enum constants.
@carterkozak carterkozak force-pushed the ckozak/case_sensitive_enums branch from 1ac4319 to 5276c58 Compare January 12, 2019 00:12
.hasExactlyArgs(UnsafeArg.of("value", "onE"));
assertThatExceptionThrownRootCause(() -> mapper.readValue("\"oNE\"", EnumExample.class))
.isInstanceOf(SafeIllegalArgumentException.class)
.hasLogMessage("Enum values must use SCREAMING_SNAKE_CASE")
Copy link
Contributor

@iamdanfox iamdanfox Jan 15, 2019

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks Dan!

Copy link
Contributor

@iamdanfox iamdanfox Jan 15, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants