aws-amplify / aws-amplify/amplify-codegen

Generated API Code Force Casting String Type into Enum Type

Open
#968 2 comments 0 reactions 0 assignees View on GitHub
bug to-be-reproduced transferred
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

I run `amplify codegen --nodownload` to generate API code, with a .yml file which looks like this:

```
projects:
schema:
schemaPath: schema.graphql
includes:
- graphql/**/*.graphql
excludes:
- ./amplify/**
extensions:
amplify:
codeGenTarget: swift
generatedFileName: aaa.swift
docsFilePath: graphql
region: us-east-2
apiId: null
maxDepth: 20
extensions:
amplify:
version: 3
```

in the `schema.graphql` I have some enum type

```
enum FareMarket {
case1
case2
case3
case4
}
```

in the generated code it created `FareMarket` correctly as an enum type but it has this:

```
public var fareMarket: FareMarket {
get {
return snapshot["fareMarket"]! as! FareMarket
}
set {
snapshot.updateValue(newValue, forKey: "fareMarket")
}
}
```

which is casting a string type into FareMarket using "as!" and caused a crash.

### Steps To Reproduce

```swift
run `amplify codegen --nodownload` with the .yml file described above
```

### Expected behavior

It should create the enum using the string value as raw value.

### Amplify Framework Version

not sure

### Amplify Categories

API

### Dependency manager

Swift PM

### Swift version

6.1

### CLI version

14.0

### Xcode version

16.3

### Relevant log output

```shell

Log Messages

INSERT LOG MESSAGES HERE

```

### Is this a regression?

No

### Regression additional context

_No response_

### Platforms

iOS

### OS Version

18.0

### Device

iPhone 16

### Specific to simulators

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.