Skip to content

feat: support Smithy intEnum shapes#713

Open
naclonts wants to merge 3 commits into
aws-controllers-k8s:mainfrom
naclonts:intenum-support
Open

feat: support Smithy intEnum shapes#713
naclonts wants to merge 3 commits into
aws-controllers-k8s:mainfrom
naclonts:intenum-support

Conversation

@naclonts

@naclonts naclonts commented Jun 18, 2026

Copy link
Copy Markdown
Member

Issue #, if available:

Description of changes: Adds support for Smithy intEnum shapes, which previously caused the generator to panic with Unsupported shape type: intEnum.

An intEnum field is surfaced on the ACK side as a named string enum (*string using the member name), and the generated SDK-conversion code maps the name to/from the underlying integer value at the SDK boundary. Includes a mwaaserverless model fixture and tests.

MWAA Serverless field EngineVersion that uses intEnum in model definition: https://github.com/aws/aws-sdk-go-v2/blob/main/codegen/sdk-codegen/aws-models/mwaa-serverless.json#L776

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

@ack-prow ack-prow Bot requested review from jlbutler and michaelhtm June 18, 2026 22:26
@ack-prow

ack-prow Bot commented Jun 18, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: naclonts
Once this PR has been reviewed and has the lgtm label, please assign michaelhtm for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knottnt knottnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@naclonts from the Smithy docs is look like intEnum provides a name for each numeric value. From a usability perspective should we be accepting that human friendly name instead of the integer?

Comment thread pkg/generate/code/set_sdk_whitebox_test.go
Comment thread pkg/apiv2/converter.go Outdated
naclonts pushed a commit to naclonts/ack-code-generator that referenced this pull request Jun 19, 2026
Address review feedback on aws-controllers-k8s#713: instead of surfacing a Smithy intEnum
as an opaque integer, surface the human-friendly member name as a named
string enum (*string) on the ACK side, bridging name <-> int32 at the
SDK boundary.

- apiv2 converter: load intEnum as a string enum, capturing each member
  name and its integer value (smithy.api#enumValue) in Shape.IntEnumValues
- set_sdk: map the name to the SDK int32 alias via a switch
- set_resource: map the SDK int32 value back to the name, guarding on the
  integer zero value (not the empty string)
- add a mwaaserverless model + generator.yaml fixture and black-box
  SetSDK/SetResource tests exercising the EngineVersion intEnum
@naclonts

Copy link
Copy Markdown
Member Author

@naclonts from the Smithy docs is look like intEnum provides a name for each numeric value. From a usability perspective should we be accepting that human friendly name instead of the integer?

Yeah, that sounds like a better user experience. Just updated to take an approach similar to Enum fields - Let me know what you think.

Nathan Clonts added 3 commits June 30, 2026 14:05
The apiv2 Smithy loader had no handling for `intEnum` shapes. aws-sdk-go-v2
renders an intEnum as a named integer type alias (e.g.
`type EngineVersion = int32`) whose operation-struct field is a non-pointer
value, and the generator's shape converter copied the `intEnum` type through
verbatim. That left `goType` to hit its default case and panic with
"Unsupported shape type: intEnum", so any service model with an intEnum field
could not be generated (it had to be ignored via generator.yaml).

Normalize `intEnum` to `integer` in createApiShape so the field is surfaced
on the ACK side as `*int64` through the existing integer path, and mark the
shape with a DefaultValue ("0") so it reuses the established value-type SDK
field assignment path (HasDefaultValue drives pointer-vs-value handling in
set_sdk.go / set_resource.go) instead of emitting pointer access against a
value field. Also handle "intEnum" defensively in goType.

Adds converter tests (intEnum -> integer + DefaultValue, integer unaffected)
and set_sdk/set_resource whitebox cases proving value (not pointer)
read/write assignment for an intEnum scalar.
Address review feedback on aws-controllers-k8s#713: instead of surfacing a Smithy intEnum
as an opaque integer, surface the human-friendly member name as a named
string enum (*string) on the ACK side, bridging name <-> int32 at the
SDK boundary.

- apiv2 converter: load intEnum as a string enum, capturing each member
  name and its integer value (smithy.api#enumValue) in Shape.IntEnumValues
- set_sdk: map the name to the SDK int32 alias via a switch
- set_resource: map the SDK int32 value back to the name, guarding on the
  integer zero value (not the empty string)
- add a mwaaserverless model + generator.yaml fixture and black-box
  SetSDK/SetResource tests exercising the EngineVersion intEnum
…intEnum members

Two correctness fixes on top of the intEnum support:

1. IsEnum() now returns false for intEnum shapes, so SDK-boundary code can
   never accidentally treat an intEnum as a plain string enum. Callers that
   legitimately want both (CRD type generation: GoCode, EnumConsts, enum tags,
   GetEnumDefs, validateShapeNames) now test IsEnum() || IsIntEnum() explicitly.
   IsNonPointerInSDK() returns true for intEnum, matching how aws-sdk-go-v2
   generates the field (a non-pointer int32 alias, e.g. `EngineVersion
   types.EngineVersion`).

2. The read path no longer guards the int->name switch with `!= 0`. Because the
   SDK field is a non-pointer int32, zero is indistinguishable from "unset", so
   a `!= 0` guard would silently drop a legitimate zero-valued intEnum member.
   The switch is now self-contained with a `default: -> nil`.

Also adds panic guards in setSDKForSlice/Map and setResourceForSlice/Map: an
intEnum nested in a list or map is not yet supported (no AWS model uses one),
and previously would have emitted code that does not compile. Failing loudly at
codegen time matches the existing panic-on-unsupported pattern.
@naclonts

naclonts commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

/retest

@ack-prow

ack-prow Bot commented Jul 1, 2026

Copy link
Copy Markdown

@naclonts: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
eks-controller-test 9ec04ac link true /test eks-controller-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Comment on lines +7033 to +7034
case "ONE":
res.EngineVersion = svcsdktypes.EngineVersion(1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, this a tough one. From what I can tell this generated code won't be forward compatible when the AWS service adds new enum values since we won't have a mapping for the string name of the new value. Just to double check with the previous approach of using an integer would the aws-sdk-go-v2 library allow us to send an integer value not included in svcsdktypes.EngineVersion?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a really good catch, I think you're right. The original int-based approach should be forwards-compatible.

That makes me lean toward going back to the int-based approach... Especially considering the MWAA controller's enum is literally just "ONE", there's not much devex improvement in seeing "ONE" versus 1, IMO. Thoughts?

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.

2 participants