janwirth / elm-coder-generator

Generate encoders and decoders for elm/json
MIT License
12 stars 1 forks source link

Encode.maybe should enclose Encode.field. #3

Open janwirth opened 4 years ago

janwirth commented 4 years ago

@twerkmeister

twerkmeister commented 4 years ago

For type

type alias TextFieldAttribs =
    { defaultValue : String
    , placeholder : String
    , kind : TextFieldKind
    , minLength : Maybe Int
    , maxLength : Maybe Int
    }

coder generator creates the following decoder which has incompatible semantics. Specifically it does not allow Values without minLength or maxLength fields

decodeTextFieldAttribs =
    Decode.map5
        TextFieldAttribs
        (Decode.field "defaultValue" Decode.string)
        (Decode.field "placeholder" Decode.string)
        (Decode.field "kind" decodeTextFieldKind)
        (Decode.field "minLength" (Decode.maybe Decode.int))
        (Decode.field "maxLength" (Decode.maybe Decode.int))
janwirth commented 4 years ago