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

[BUG] 5.0 produces invalid Elm code with missing decoders/encoders for custom types #8343

Open
SiriusStarr opened this issue Jan 5, 2021 · 1 comment

Comments

@SiriusStarr
Copy link

SiriusStarr commented Jan 5, 2021

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 #8218 (comment)

@SiriusStarr
Copy link
Author

Just pulled and confirmed that the issue with custom types persists in the latest master, 04dfff8. The issue with the erroneous decoder appears to have been fixed, however, so I have struckout that above.

mawis added a commit to mawis/openapi-generator that referenced this issue Sep 5, 2021
As described in
OpenAPITools#8343 invalid
code was generated when the OpenAPI uses enums. With this the
decoders/encoders are called at the correct place.
wing328 pushed a commit that referenced this issue Sep 8, 2021
As described in
#8343 invalid
code was generated when the OpenAPI uses enums. With this the
decoders/encoders are called at the correct place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant