Open manaswi223 opened 1 year ago
Hi @manaswi223, your fix sounds like the right approach, and this appears to compile for me
// swiftlint:disable all
import Amplify
import Foundation
public struct Break: Embeddable {
var break_id: Int?
var payment_mode: String?
}
extension Break {
// MARK: - CodingKeys
public enum CodingKeys: String, ModelKey {
case break_id
case payment_mode
}
public static let keys = CodingKeys.self
// MARK: - ModelSchema
public static let schema = defineSchema { model in
let `break` = Break.keys
model.pluralName = "Breaks"
model.fields(
.field(`break`.break_id, is: .optional, ofType: .int),
.field(`break`.payment_mode, is: .optional, ofType: .string)
)
}
}
You probably missed the backticks at these two lines:
Considering "break" is a special keyword in Swift, we should either globally denylist this word when compiling the GraphQL schema.graphql or generate the backticks with the word "break" for Swift. Does the schema break on other platforms such as Flutter, JS or Android?
Thank you for reporting @manaswi223 - we currently don't maintain a platform-specific denylist as far as I'm aware, but logging this as a feature request.
Describe the bug
An embedded type model named
Break
fails to compile on Xcode complaining about reserved keywords although the codegen generates code & compiles it successfully.The build fail error:
Keyword 'break' cannot be used as an identifier here
As a fix, tried to add a backtick to the break keyword in the generated files, but still fails complaining about missing parameter:
Steps To Reproduce
Expected behavior
scenario 1:
amplify codegen models
successfully generates codegenerated files & code builds on Xcode (after a potential bug-fix)scenario 2:
amplify codegen models
throws error on the CLI to consider renaming embedded types in their schemas to avoid usage of the reserved keywords on XcodeAmplify Framework Version
main
Amplify Categories
DataStore
Dependency manager
Cocoapods
Swift version
5.0
CLI version
9.1.0
Xcode version
14.0.1
Relevant log output