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
  • #310
Closed
Open
Issue created Jun 13, 2018 by Administrator@rootContributor

[elm-client] Recursive type aliases

Created by: andys8

A recursive data structure will lead to elm code, which is not being parsed. The main issue and how to workaround is described here: https://github.com/elm/compiler/blob/0.18.0/hints/recursive-alias.md

    "tags": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
        },
        "children": {
          "type": "array",
          "items": { "$ref": "#/definitions/tags" }
        }
      }
    }

Will generate this:

type alias Tags =
    { id : UUID
    , children : List Tags
    }


tagsDecoder : Decoder Tags
tagsDecoder =
    decode Tags
        |> required "id" uUIDDecoder
        |> required "children" (Decode.list tagsDecoder)


tagsEncoder : Tags -> Encode.Value
tagsEncoder model =
    Encode.object
        [ ( "id", uUIDEncoder model.id )
        , ( "children", (Encode.list << List.map tagsEncoder) model.children )
        ]

But should be something like this, where Decode.lazy is used and a type definition for the recursive list:

type alias Tags =
    { id : UUID
    , children : Children
    }


type Children
    = Children (List Tags)


childrenToTags : Children -> List Tags
childrenToTags (Children tags) =
    tags


tagsDecoder : Decoder Tags
tagsDecoder =
    decode Tags
        |> required "id" uUIDDecoder
        |> required "children"
            (Decode.map Children (Decode.list (Decode.lazy (\_ -> tagsDecoder))))


tagsEncoder : Tags -> Encode.Value
tagsEncoder model =
    Encode.object
        [ ( "id", uUIDEncoder model.id )
        , ( "children", (Encode.list << List.map tagsEncoder) (childrenToTags model.children) )
        ]

OpenAPI spec version: 0.4.0 Generator version 3.0.1

Assignee
Assign to
Time tracking