A Swift macro that automatically generates CodingKeys enums for Codable structs, classes and actors. It converts property names from camelCase to snake_case by default and supports custom key mapping via the @KeyAlias("custom_key") attribute. No more manual key mapping—just annotate and go.
@AutoKey
struct SomeModel: Codable {
let someString: String?
let someInt: Int?
@KeyAlias("some_other_int") let anotherInt: Int?
}
will be expanded to:
struct SomeModel: Codable {
let someString: String?
let someInt: Int?
let anotherInt: Int?
private enum CodingKeys: String, CodingKey {
case someString = "some_string"
case someInt = "some_int"
case anotherInt = "some_other_int"
}
}