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.

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.
@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?

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.

In addition to the white box tests it would also be good to setup some test cases in set_resource_test.go and set_sdk_test.go for the particular service controller use case. For setting up the test you can add the controller model and a sample generator.yaml file to the pkg/test_data directory.

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.

Sounds good, added some test cases there, with new mwaaserverless models.

Comment thread pkg/apiv2/converter.go Outdated
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.

…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.
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