Skip to content

fix: Fix default value for string-backed enums #939

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

Merged
merged 2 commits into from
Jun 20, 2025

Conversation

jbelkins
Copy link
Contributor

@jbelkins jbelkins commented Jun 20, 2025

Description of changes

Fixes code for determining default value for Smithy Enum types (i.e. Swift enum w/ raw value of type String.)

The previous default value code was incorrect (it constructed an enum case name from the raw value when those two values are not necessarily related.) It worked for names that closely match the raw value and do not contain numbers. A pending model change breaks these assumptions, and a compile error results.

Instead, the approach for determining IntEnum raw values is adapted, which is correct - search the Smithy Enum's members to find one whose raw value matches the default value, then use the name of that member to derive the Swift default value.

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jbelkins jbelkins requested review from dayaffe and sichanyoo June 20, 2025 20:37
@jbelkins jbelkins marked this pull request as ready for review June 20, 2025 20:44
@jbelkins jbelkins merged commit 54c2aaa into main Jun 20, 2025
33 checks passed
@jbelkins jbelkins deleted the jbe/enum_default_value_fix branch June 20, 2025 21:35
@jbelkins jbelkins changed the title chore: Fix default value for string-backed enums fix: Fix default value for string-backed enums Jun 20, 2025
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 this pull request may close these issues.

3 participants