-
Notifications
You must be signed in to change notification settings - Fork 6k
Open
Description
Description
Current code generator for Swift 4 generates invalid code for JSON dictionaries or properties with object value type.
Property generated code:
open class TaskParameter: Codable {
public var id: String?
public var value: Any?
public init() {}
}
Dictionary generated code:
open class EntityKey: Codable {
public var entity: String?
public var alias: String?
public var fields: [String:Any]?
public init() {}
}
Swagger-codegen version
2.2.3
Swagger declaration file content or url
"definitions": {
"TaskParameter": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"value": {
"type": "object"
}
}
},
"EntityKey": {
"type": "object",
"properties": {
"entity": {
"type": "string"
},
"alias": {
"type": "string"
},
"fields": {
"type": "object",
"additionalProperties": {
"type": "object"
}
}
}
}
}Command line used for generation
swagger-codegen generate -i ./swagger.json -l swift4 -o ./api
Steps to reproduce
Generate the code with swagger-codegen 2.2.3 then try to compile the generated classes on Xcode 9 GM or any beta version.
Related issues/PRs
Suggest a fix/enhancement
Seems like this problem relies on the fact that Any is not (and will be not) Codable, thus a generic "AnyCodable" that conforms to this protocol should be used instead.
Jorgiss, Shah0786, vntguca, MihaylovArtem, TakenakaSimon and 11 morevntguca
Metadata
Metadata
Assignees
Labels
No labels