From 10a20c741c12035dc03d30d3746367b19cbcb27d Mon Sep 17 00:00:00 2001 From: Gustavo Diaz Date: Mon, 16 Mar 2026 21:35:21 +0000 Subject: [PATCH] Include idempotency token by default --- pkg/config/resource.go | 14 ++++--- pkg/generate/code/set_sdk_test.go | 39 ++++++++++++------- pkg/model/model.go | 13 ++++--- pkg/model/model_ec2_test.go | 1 - .../generator-include-idempotency-token.yaml | 14 +++++++ .../emr-serverless/0000-00-00/generator.yaml | 1 - 6 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 pkg/testdata/models/apis/emr-serverless/0000-00-00/generator-include-idempotency-token.yaml diff --git a/pkg/config/resource.go b/pkg/config/resource.go index 4e63fdbf..23b4df58 100644 --- a/pkg/config/resource.go +++ b/pkg/config/resource.go @@ -116,12 +116,14 @@ type ResourceConfig struct { // TagConfig contains instructions for the code generator to generate // custom code for ensuring tags TagConfig *TagConfig `json:"tags,omitempty"` - // IgnoreIdempotencyToken instructs the code generator to automatically - // exclude fields that have the smithy.api#idempotencyToken trait (or the - // equivalent idempotencyToken trait in the v1 SDK model). These fields are - // SDK implementation details that are auto-filled by the SDK middleware - // when nil and should not be exposed in the CRD. - IgnoreIdempotencyToken bool `json:"ignore_idempotency_token,omitempty"` + // IncludeIdempotencyToken instructs the code generator to keep fields + // that have the smithy.api#idempotencyToken trait (or the equivalent + // idempotencyToken trait in the v1 SDK model). By default, these fields + // are automatically excluded because they are SDK implementation details + // that are auto-filled by the SDK middleware when nil and should not be + // exposed in the CRD. Set this to true only if you need to expose + // idempotency token fields in the CRD. + IncludeIdempotencyToken bool `json:"include_idempotency_token,omitempty"` } // TagConfig instructs the code generator on how to generate functions that diff --git a/pkg/generate/code/set_sdk_test.go b/pkg/generate/code/set_sdk_test.go index b2ae107b..957a91e2 100644 --- a/pkg/generate/code/set_sdk_test.go +++ b/pkg/generate/code/set_sdk_test.go @@ -2207,9 +2207,6 @@ func TestSetSDK_MQ_Broker_Create(t *testing.T) { } res.Configuration = f3 } - if r.ko.Spec.CreatorRequestID != nil { - res.CreatorRequestId = r.ko.Spec.CreatorRequestID - } if r.ko.Spec.DeploymentMode != nil { res.DeploymentMode = svcsdktypes.DeploymentMode(*r.ko.Spec.DeploymentMode) } @@ -5179,9 +5176,6 @@ func TestEMRContainers_VirtualCluster_WithUnion(t *testing.T) { assert.NotNil(crd.Ops.Create) expected := ` - if r.ko.Spec.ClientToken != nil { - res.ClientToken = r.ko.Spec.ClientToken - } if r.ko.Spec.ContainerProvider != nil { f1 := &svcsdktypes.ContainerProvider{} if r.ko.Spec.ContainerProvider.ID != nil { @@ -6496,11 +6490,10 @@ func TestSetSDK_EMRServerless_Application_Create(t *testing.T) { "Should use original SDK shape name WorkerTypeSpecificationInput, not renamed version") // Verify idempotency token fields are excluded from the generated code - // when ignore_idempotency_token is enabled on the resource in generator.yaml. - // The ClientToken field in CreateApplicationInput has the - // smithy.api#idempotencyToken trait, and the emr-serverless test config - // has ignore_idempotency_token: true on Application, so the code generator - // should exclude it from the CRD and generated SDK code. The SDK middleware + // by default. The ClientToken field in CreateApplicationInput has the + // smithy.api#idempotencyToken trait, so the code generator should + // exclude it from the CRD and generated SDK code unless + // include_idempotency_token is set to true. The SDK middleware // auto-fills it with a UUID when nil. assert.NotContains(got, "ClientToken", "ClientToken (idempotency token) should not appear in Create SDK code") @@ -6535,8 +6528,7 @@ func TestSetSDK_EMRServerless_Application_Update(t *testing.T) { "Should use original SDK shape name in Update operation") } - // Verify idempotency token fields are excluded from Update as well - // when ignore_idempotency_token is enabled on the resource. + // Verify idempotency token fields are excluded from Update by default. // UpdateApplicationInput.ClientToken also has the // smithy.api#idempotencyToken trait. assert.NotContains(got, "ClientToken", @@ -6566,6 +6558,27 @@ func TestSetSDK_EMRServerless_Application_InitialCapacityConfig(t *testing.T) { assert.Contains(got, "WorkerCount") } +// TestSetSDK_EMRServerless_Application_IncludeIdempotencyToken tests that +// setting include_idempotency_token: true in generator.yaml causes the +// ClientToken field to appear in the generated SDK code. +func TestSetSDK_EMRServerless_Application_IncludeIdempotencyToken(t *testing.T) { + assert := assert.New(t) + require := require.New(t) + + g := testutil.NewModelForServiceWithOptions(t, "emr-serverless", &testutil.TestingModelOptions{ + GeneratorConfigFile: "generator-include-idempotency-token.yaml", + }) + + crd := testutil.GetCRDByName(t, g, "Application") + require.NotNil(crd) + + got, err := code.SetSDK(crd.Config(), crd, model.OpTypeCreate, "r.ko", "res", 1) + require.NoError(err) + + assert.Contains(got, "ClientToken", + "ClientToken should appear in Create SDK code when include_idempotency_token is true") +} + // TestSetSDK_QuickSight_DataSet_Create tests that the SetSDK code generation // for the QuickSight DataSet resource correctly handles: // diff --git a/pkg/model/model.go b/pkg/model/model.go index d703655c..796751b2 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -177,12 +177,13 @@ func (m *Model) GetCRDs() ([]*CRD, error) { // Idempotency tokens are SDK implementation details that are // auto-filled by the SDK middleware when nil. They should not // be exposed in the CRD as they are not resource properties. - // This filtering is opt-in via resources..ignore_idempotency_token - // in generator.yaml. - resConfig := m.cfg.GetResourceConfig(crdName) - if resConfig != nil && resConfig.IgnoreIdempotencyToken && - (memberShapeRef.IdempotencyToken || memberShapeRef.Shape.IdempotencyToken) { - continue + // This filtering is on by default. Set include_idempotency_token + // to true in generator.yaml to keep these fields. + if memberShapeRef.IdempotencyToken || memberShapeRef.Shape.IdempotencyToken { + resConfig := m.cfg.GetResourceConfig(crdName) + if resConfig == nil || !resConfig.IncludeIdempotencyToken { + continue + } } // If this is the wrapper field and we have input_wrapper_field_path diff --git a/pkg/model/model_ec2_test.go b/pkg/model/model_ec2_test.go index d39c8af6..f6c74102 100644 --- a/pkg/model/model_ec2_test.go +++ b/pkg/model/model_ec2_test.go @@ -126,7 +126,6 @@ func TestEC2_Volume(t *testing.T) { expSpecFieldCamel := []string{ "AvailabilityZone", - "ClientToken", "DryRun", "Encrypted", "IOPS", diff --git a/pkg/testdata/models/apis/emr-serverless/0000-00-00/generator-include-idempotency-token.yaml b/pkg/testdata/models/apis/emr-serverless/0000-00-00/generator-include-idempotency-token.yaml new file mode 100644 index 00000000..7f0e6014 --- /dev/null +++ b/pkg/testdata/models/apis/emr-serverless/0000-00-00/generator-include-idempotency-token.yaml @@ -0,0 +1,14 @@ +ignore: + resource_names: [] + field_paths: + - Configuration.Configurations +sdk_names: + model_name: emr-serverless +resources: + Application: + include_idempotency_token: true + fields: + WorkerTypeSpecifications: + from: + operation: GetApplication + path: Application.WorkerTypeSpecifications diff --git a/pkg/testdata/models/apis/emr-serverless/0000-00-00/generator.yaml b/pkg/testdata/models/apis/emr-serverless/0000-00-00/generator.yaml index 0171c68c..e43427e2 100644 --- a/pkg/testdata/models/apis/emr-serverless/0000-00-00/generator.yaml +++ b/pkg/testdata/models/apis/emr-serverless/0000-00-00/generator.yaml @@ -6,7 +6,6 @@ sdk_names: model_name: emr-serverless resources: Application: - ignore_idempotency_token: true fields: WorkerTypeSpecifications: from: