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

Should Enums be allowed to have empty string values? #627

Closed
jasdel opened this issue Nov 9, 2020 · 2 comments · Fixed by #633
Closed

Should Enums be allowed to have empty string values? #627

jasdel opened this issue Nov 9, 2020 · 2 comments · Fixed by #633

Comments

@jasdel
Copy link
Contributor

jasdel commented Nov 9, 2020

What, if any limitations are there on the values of an string decorated with the @enum trait? Specifically, Should it be valid for enum's to be modeled with empty string values? I'm asking this question because it will direclty drive how the v2 AWS SDK for Go is able to codegen enum shapes.

I'd like to suggest that enum shapes should not be modeled with enum values of empty string. With validation returning and error if there are empty string value enums.

This question and proposal is similar to stating enum strings have a default value, i.e. empty string. This default value allows SDK to not need to distinguish the difference between unset and empty string. This removes the need for languages like Go to use pointers (aka optional) for enum shapes. The zero value (default) of the enum type would be equivalent to the unset or empty string value.

With this proposal, code generators for languages like Go would not distinguish the difference between unset, null, or empty string of enum values during deserialization. During serialization a unset,null,empty string would also be interpreted as unset, and not be serialized. Or in case of sparse list/map serialized as the protocol's null value.

@kstich
Copy link
Contributor

kstich commented Nov 9, 2020

The value property of a definition in the @enum trait is defined as a string with a minimum length of 1. We can update the specification to state this more clearly, but the proposed state is already the case in implementation. An empty value would throw a model validation error like this:

Model:

namespace ns.foo

@enum([{value: ""}])
string Invalid

Error:

[Error] ns.foo#Invalid: Error validating trait `enum`.0.value: String value provided for `smithy.api#NonEmptyString` must be >= 1 characters, but the provided value is only 0 characters. | TraitValue N/A:0:0

@jasdel
Copy link
Contributor Author

jasdel commented Nov 9, 2020

Thanks for the feedback! I wasn't aware of the minimum length trait on enum values. This is very helpful. I think with that information it clarifies that the v2 AWS SDK for Go could safely render enum shapes as values, not pointers (aka optional). Since the SDK can use the empty string to identify that the user of the SDK has not provided a valid value.

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

Successfully merging a pull request may close this issue.

2 participants