OpenAPITools / OpenAPITools/openapi-generator
[BUG][Elm] invalid code is generated for array of enum strings
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When generating Elm code with a schema that has an array property with items of type string enum, the generated code is invalid. The encoder tries to encode the enum as an integer, which is incorrect. The function it tries to reference does not exist.
openapi-generator version
7.16.0
OpenAPI declaration file content or url
{
"openapi" : "3.0.1",
"info" : {
"title" : "OpenAPI definition",
"version" : "v0"
},
"servers" : [ {
"url" : "http://127.0.0.1:4000",
"description" : "Generated server url"
} ],
"paths": {},
"components" : {
"schemas" : {
"TestObject" : {
"type" : "object",
"properties" : {
"body" : {
"type" : "array",
"items": {
"type" : "string",
"enum" : [ "ENUM_FIRST", "ENUM_SECOND", "ENUM_THIRD" ]
}
}
}
}
}
}
}
Generation Details
npx @openapitools/openapi-generator-cli generate -i openapi.json -g elm -o elm
Steps to reproduce
Run the generated command, see that the generated file contains:
encodeTestObjectBody : TestObjectBody -> Json.Encode.Value
encodeTestObjectBody =
Json.Encode.int << intFromTestObjectBody
while it should be
encodeTestObjectBody : TestObjectBody -> Json.Encode.Value
encodeTestObjectBody =
Json.Encode.string << stringFromTestObjectBody
Suggest a fix
See above. Fix is to correctly interpret the enum as a string.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied OpenAPI declaration and the npx @openapitools/openapi-generator-cli generate -i openapi.json -g elm -o elm command. Inspect the generated encodeTestObjectBody output and verify that the array of string enum values uses Json.Encode.string and the generated Elm code is valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elm, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100