[SWIFT4] Default values for ENUMs are using strings instead of the enum
Created by: grEvenX
Description
OpenAPI 3.0.0 has support for strings in enum
format. The Swift4 generator maps these into enum
in the Swift code which works fine. However if you provide a default
value in the OpenAPI document, the values for the properties of enum types are set as strings instead of the enum which again causes the compiler to fail.
openapi-generator version
3.1.2
OpenAPI declaration file content or url
https://gist.github.com/grEvenX/76d508f2933456894492c38410b1ac49
Command line used for generation
docker run --rm -v $(pwd)/generated:/out openapitools/openapi-generator-cli:latest generate -i https://gist.githubusercontent.com/grEvenX/76d508f2933456894492c38410b1ac49/raw/6e3a93cc3bc219815769a21fdcad84628ab0af59/example.yaml -g swift4 -o /out/swift4
Steps to reproduce
- Run the following docker command to generate a Swift4 client with the example YAML using enums and default values
- Inspect the output of
generated/swift4/OpenAPIClient/Classes/OpenAPIs/Models/NewPet.swift
Suggest a fix/enhancement
The generated model contains the line:
public enum Animal: String, Codable {
case dog = "dog"
case cat = "cat"
}
public var animal: Animal? = "cat"
The correct value that should be assigned to animal
in this case is:
public var animal: Animal? = .cat