Swift modelgen creates wrong decoding initializer with optional custom type in required array #8937
Labels
bug
This issue is a bug.
closing-soon
This issue will automatically close in 4 days unless further comments are made.
p2
This is a standard priority issue
Describe the bug
When running
npx ampx generate graphql-client-code --format modelgen --model-target swift
on my Amplify Swift project, depending on the models defined indata/resource.ts
the decoding initializer does not compile due to aCannot assign value of type '[MyCustomType]?' to type '[MyCustomType?]
error in Xcode.Expected Behavior
myCustomTypes = try values.decode([MyCustomType?].self, forKey: .myCustomTypes)
should be generatedCurrent Behavior
myCustomTypes = try? values.decode([MyCustomType].self, forKey: .myCustomTypes)
is generatedReproduction Steps
Define the following models in
data/resource.ts
:And run
npx ampx generate graphql-client-code --format modelgen --model-target swift
to create the models.Possible Solution
No response
Additional Information/Context
When changing the custom type in the array to a non-optional, the decoding is done correctly.
CLI version used
aws-cli/2.17.56 Python/3.12.6 Darwin/24.1.0 source/arm64
Environment details (OS name and version, etc.)
macOS 15.1, Xcode 16.1 beta 2, swift-tools-version: 6.0, swiftLanguageModes v5
The text was updated successfully, but these errors were encountered: