OpenAPITools / OpenAPITools/openapi-generator
[BUG] 5.0 produces invalid Elm code with missing decoders/encoders for custom types
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
In the petstore example, it looks like custom types's don't have their encoders/decoders properly written:
orderDecoder : Json.Decode.Decoder Order_
orderDecoder =
Json.Decode.succeed Order_
|> maybeDecode "id" Json.Decode.int Nothing
|> maybeDecode "petId" Json.Decode.int Nothing
|> maybeDecode "quantity" Json.Decode.int Nothing
|> maybeDecode "shipDate" Api.Time.dateTimeDecoder Nothing
|> maybeDecode "status" <!!orderStatusDecoder should be here!!> Nothing
|> maybeDecode "complete" Json.Decode.bool (Just False)
encodeOrderPairs : Order_ -> List EncodedField
encodeOrderPairs model =
let
pairs =
[ maybeEncode "id" Json.Encode.int model.id
, maybeEncode "petId" Json.Encode.int model.petId
, maybeEncode "quantity" Json.Encode.int model.quantity
, maybeEncode "shipDate" Api.Time.encodeDateTime model.shipDate
, maybeEncode "status" <!!encodeOrderStatus should be here!!> model.status
, maybeEncode "complete" Json.Encode.bool model.complete
]
in
pairs
Additionally, there is an erroneous DEcoder in the middle of one of the ENcoders. fixed in master
This is the full diff between the output of 04dfff8 and a manually corrected version:
diff -r elm-openapi-test/src/Api/Data.elm elm-openapi-test-fix/src/Api/Data.elm
202c202
< , maybeEncode "status" model.status
---
> , maybeEncode "status" encodeOrderStatus model.status
246c246
< , maybeEncode "status" model.status
---
> , maybeEncode "status" encodePetStatus model.status
343c343
< |> maybeDecode "status" Nothing
---
> |> maybeDecode "status" orderStatusDecoder Nothing
376c376
< |> maybeDecode "status" Nothing
---
> |> maybeDecode "status" petStatusDecoder Nothing
Originally posted by @SiriusStarr in https://github.com/OpenAPITools/openapi-generator/issues/8218#issuecomment-747686514
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
The petstore output is shown in elm-openapi-test/src/Api/Data.elm; start by comparing it with the corrected diff and trace the Elm custom-type generation path. Done means generated Order_ and Pet_ code includes the corresponding status decoders and encoders, matching the listed corrections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elm
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100