Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SWIFT4] Default values for ENUMs are using strings instead of the enum #652

Closed
grEvenX opened this issue Jul 26, 2018 · 3 comments
Closed

Comments

@grEvenX
Copy link
Contributor

grEvenX commented Jul 26, 2018

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
  1. Run the following docker command to generate a Swift4 client with the example YAML using enums and default values
  2. 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
@albator1932
Copy link
Contributor

I wonder if this could be related to my issue 😦
I may be wrong but it looks close enough to #635

grEvenX added a commit to grEvenX/openapi-generator that referenced this issue Jul 26, 2018
This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value.
The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value.
Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation.
@grEvenX
Copy link
Contributor Author

grEvenX commented Aug 21, 2018

@wing328 What's needed to "tag'n bag" this issue? :)

wing328 pushed a commit that referenced this issue Sep 9, 2018
This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value.
The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value.
Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation.
jaumard pushed a commit to jaumard/openapi-generator that referenced this issue Sep 21, 2018
…#656)

This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value.
The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value.
Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation.
@grEvenX
Copy link
Contributor Author

grEvenX commented Oct 18, 2018

This was resolved in pull-request #656 and released in v3.3.0

@grEvenX grEvenX closed this as completed Oct 18, 2018
@wing328 wing328 added this to the 3.3.0 milestone Dec 3, 2018
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this issue Feb 27, 2019
…#656)

This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value.
The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value.
Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants