swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
public struct Foo: Codable {
public enum ModelType: String, Codable {
case bar = "Bar"
}
public var modelType: ModelType
public init(modelType: ModelType) {
self.modelType = modelType
}
}
Bar:
public struct Bar: Codable {
public enum ModelType: String, Codable {
}
public var modelType: ModelType
public var name: String
public init(modelType: ModelType, name: String) {
self.modelType = modelType
self.name = name
}
}
In Bar struct you can see enum without any case which won't compile.
When using the same yaml file but generating swift3 client - everything is fine.
Possible fix may be generating Bar in the following way:
public struct Bar: Codable {
public typealias ModelType = Foo.ModelType
public var modelType: ModelType
public var name: String
public init(modelType: ModelType, name: String) {
self.modelType = modelType
self.name = name
}
}
Description
Issue appears when generating swift4 client and in *.yaml file you have model with enum discriminator. Example of models definition:
Generated models: Foo:
Bar:
In Bar struct you can see enum without any case which won't compile. When using the same yaml file but generating swift3 client - everything is fine.
Swagger-codegen version
swagger-codegen version is 2.4.7
Command line used for generation
swagger-codegen generate -i api.yaml -l swift4 -o client
Suggest a fix/enhancement
Possible fix may be generating Bar in the following way: