Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8343
Closed
Open
Issue created Jan 05, 2021 by Administrator@rootContributor

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

Created by: SiriusStarr

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 04dfff83 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

Assignee
Assign to
Time tracking