We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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:
Decode.lazy
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
The text was updated successfully, but these errors were encountered:
This is now part of the upcoming 5.0.0 release.
Sorry, something went wrong.
No branches or pull requests
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
Will generate this:
But should be something like this, where
Decode.lazy
is used and a type definition for the recursive list:OpenAPI spec version: 0.4.0
Generator version 3.0.1
The text was updated successfully, but these errors were encountered: