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

Use type's default for default stub map key #76

Conversation

knovichikhin
Copy link
Contributor

Some models use specific non-primitive type
for a map key, such as an enum. Not resolving
to that results in a compilation failure.

Issue #, if available:

The particular issue is in smoke-aws. When building AppConfig model default instance ends up with:

     static let __default: AppConfigModel.CreateExtensionRequest = {
         let defaultInstance = AppConfigModel.CreateExtensionRequest(
            actions: ["Entry_0": [Action.__default]],
             description: nil,
             latestVersionNumber: nil,
             name: "0",

After this change the default instance will be:

     static let __default: AppConfigModel.CreateExtensionRequest = {
         let defaultInstance = AppConfigModel.CreateExtensionRequest(
            actions: [ActionPoint.__default: [Action.__default]],
             description: nil,
             latestVersionNumber: nil,
             name: "0",

Description of changes:

When building a default instance, resolve key to a specific default value for that type if possible.

Running smoke-aws-generate with this build results in the following changes:

--- a/Sources/AppConfigModel/AppConfigModelDefaultInstances.swift
+++ b/Sources/AppConfigModel/AppConfigModelDefaultInstances.swift
@@ -292,7 +292,7 @@ public extension CreateExtensionRequest {
      */
     static let __default: AppConfigModel.CreateExtensionRequest = {
         let defaultInstance = AppConfigModel.CreateExtensionRequest(
-            actions: ["Entry_0": [Action.__default]],
+            actions: [ActionPoint.__default: [Action.__default]],
             description: nil,
             latestVersionNumber: nil,
             name: "0",
diff --git a/Sources/CloudformationModel/CloudformationModelDefaultInstances.swift b/Sources/CloudformationM
odel/CloudformationModelDefaultInstances.swift
index 3deb8b9..c9baec4 100644
--- a/Sources/CloudformationModel/CloudformationModelDefaultInstances.swift
+++ b/Sources/CloudformationModel/CloudformationModelDefaultInstances.swift
@@ -2830,7 +2830,7 @@ public extension ResourceToImport {
     static let __default: CloudformationModel.ResourceToImport = {
         let defaultInstance = CloudformationModel.ResourceToImport(
             logicalResourceId: "value",
-            resourceIdentifier: ["Entry_0": "0"],
+            resourceIdentifier: ["0": "0"],
             resourceType: "0")

         return defaultInstance
diff --git a/Sources/DynamoDBModel/DynamoDBModelDefaultInstances.swift b/Sources/DynamoDBModel/DynamoDBModelDefaultInstances.swift
index 31cfced..9bf6dfc 100644
--- a/Sources/DynamoDBModel/DynamoDBModelDefaultInstances.swift
+++ b/Sources/DynamoDBModel/DynamoDBModelDefaultInstances.swift
@@ -280,7 +280,7 @@ public extension BatchGetItemInput {
      */
     static let __default: DynamoDBModel.BatchGetItemInput = {
         let defaultInstance = DynamoDBModel.BatchGetItemInput(
-            requestItems: ["Entry_0": KeysAndAttributes.__default],
+            requestItems: ["012": KeysAndAttributes.__default],
             returnConsumedCapacity: nil)

         return defaultInstance
@@ -350,7 +350,7 @@ public extension BatchWriteItemInput {
      */
     static let __default: DynamoDBModel.BatchWriteItemInput = {
         let defaultInstance = DynamoDBModel.BatchWriteItemInput(
-            requestItems: ["Entry_0": [WriteRequest.__default]],
+            requestItems: ["012": [WriteRequest.__default]],
             returnConsumedCapacity: nil,
             returnItemCollectionMetrics: nil)

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

Some models use specific non-primitive type
for a map key, such as an enum. Not resolving
to that results in a compilation failure.
Copy link
Contributor

@tachyonics tachyonics left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

@knovichikhin knovichikhin merged commit 65e5e80 into amzn:service-model-swift-code-generate-2.x Nov 4, 2023
3 checks passed
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