Swift modelgen creates wrong decoding initializer with optional custom type in required arra #885
Labels
bug
Something isn't working
Gen 2
transferred
Issue has been transferred from another Amplify repository
Environment information
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.Additional Information/Context
When changing the custom type in the array to a non-optional, the decoding is done correctly.
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: