Bug Report Checklist
Description
When encoding or decoding Swift string enums to json or to a http url, sometimes the value that is used it's the case name instead of the rawValue.
openapi-generator version
4.2.1
OpenAPI declaration file content or url
Here is an example that show's the bug.
https://gist.github.com/4brunu/0bb9de272f84794554bcf73db7c514bb
Command line used for generation
openapi-generator generate \
--input-spec openapi.yaml \
--generator-name swift4 \
--config openapi-config.json \
--output openapi/
Here is a link to a sample project that demonstrates the issue.
https://github.com/4brunu/openapi-generator-swift-enum-http-parameter
Steps to reproduce
The problem is here
https://github.com/4brunu/openapi-generator-swift-enum-http-parameter/blob/d64978a556ed21c1d78730b2fc102a91eda50a1d/openapi/OpenAPIClient/Classes/OpenAPIs/APIs/OperationsAPI.swift#L39-L50
The problem is in line 39
category is of type MotivesCategory which is an enum, so the value that should be used is the rawValue, otherwise, the value that will be used it's the name of the case, not the value of the case.
To fix the problem, the line 39 should be - "category": category.rawValue
let me show an example to explain the problem
let categoryTemp = MotivesCategory.createOperation
print(categoryTemp) // output: createOperation
print(categoryTemp.rawValue) // output: CREATE_OPERATION which is the right value
Suggest a fix
The thing that I don't understand is the here
|
"{{baseName}}": {{paramName}}{{^isEnum}}{{#isInteger}}{{^required}}?{{/required}}.encodeToJSON(){{/isInteger}}{{#isLong}}{{^required}}?{{/required}}.encodeToJSON(){{/isLong}}{{/isEnum}}{{#isEnum}}{{^isContainer}}{{^required}}?{{/required}}.rawValue{{/isContainer}}{{/isEnum}}{{#isDate}}{{^required}}?{{/required}}.encodeToJSON(){{/isDate}}{{#isDateTime}}{{^required}}?{{/required}}.encodeToJSON(){{/isDateTime}} |
If the type is an enum and it's not a container, which is not, it should add the
.rawValue, but it's not.
In some enum's it add's the
rawValue but not here.
Is this not an enum?
Bug Report Checklist
Description
When encoding or decoding Swift string enums to json or to a http url, sometimes the value that is used it's the case name instead of the rawValue.
openapi-generator version
4.2.1
OpenAPI declaration file content or url
Here is an example that show's the bug.
https://gist.github.com/4brunu/0bb9de272f84794554bcf73db7c514bb
Command line used for generation
Here is a link to a sample project that demonstrates the issue.
https://github.com/4brunu/openapi-generator-swift-enum-http-parameter
Steps to reproduce
The problem is here
https://github.com/4brunu/openapi-generator-swift-enum-http-parameter/blob/d64978a556ed21c1d78730b2fc102a91eda50a1d/openapi/OpenAPIClient/Classes/OpenAPIs/APIs/OperationsAPI.swift#L39-L50
The problem is in line 39
category is of type
MotivesCategorywhich is an enum, so the value that should be used is the rawValue, otherwise, the value that will be used it's the name of the case, not the value of the case.To fix the problem, the line 39 should be - "category": category.rawValue
Suggest a fix
The thing that I don't understand is the here
openapi-generator/modules/openapi-generator/src/main/resources/swift4/_param.mustache
Line 1 in 8cf34ca
If the type is an enum and it's not a container, which is not, it should add the
.rawValue, but it's not.In some enum's it add's the
rawValuebut not here.Is this not an enum?