All Downloads are FREE. Search and download functionalities are using the official Maven repository.

elm.modelTypeDiscriminator.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
type {{classname}}
{{#children}}
    {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{classname}}Type {{classname}}
{{/children}}


{{classVarName}}Decoder : Decoder {{classname}}
{{classVarName}}Decoder =
    Decode.field "{{discriminator}}" Decode.string
        |> Decode.andThen {{classVarName}}TypeDecoder


{{classVarName}}TypeDecoder : String -> Decoder {{classname}}
{{classVarName}}TypeDecoder {{discriminator}} =
    case {{discriminator}} of
{{#children}}
        "{{vendorExtensions.x-discriminator-value}}" ->
            Decode.map {{classname}}Type {{classVarName}}Decoder

{{/children}}
        _ ->
            Decode.fail <|
                "Trying to decode {{classname}}, but {{discriminator}} "
                ++ toString {{discriminator}} ++ " is not supported."


{{classVarName}}Encoder : {{classname}} -> Encode.Value
{{classVarName}}Encoder model =
    case model of
{{#children}}
        {{classname}}Type subModel ->
            {{classVarName}}Encoder subModel

{{/children}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy