Skip to content

Commit 05db32f

Browse files
laughedelicwing328
authored andcommitted
[Elm] Template improvements (#661)
* Add elm template parameter to the samples testing script * Update elm-date-extra package; fixes #458 * Update generated elm samples * Use Elm doc comments; remove some unneccessary newlines * Update generated Elm samples * Remove unnecessary parenthesis around non-optional container type
1 parent c116c8f commit 05db32f

23 files changed

Lines changed: 57 additions & 144 deletions

bin/elm-petstore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ fi
2727

2828
# if you've executed sbt assembly previously it will use that instead.
2929
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
30-
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -o samples/client/petstore/elm $@"
30+
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/client/petstore/elm $@"
3131

3232
java $JAVA_OPTS -jar $executable $ags

modules/openapi-generator/src/main/resources/elm/DateOnly.mustache

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Date
44
import Date.Extra exposing (fromIsoString, toFormattedString)
55
import Json.Decode as Decode exposing (Decoder)
66
import Json.Encode as Encode
7+
import Result
78

89

910
type alias DateOnly =
@@ -24,11 +25,8 @@ dateOnlyEncoder model =
2425
decodeIsoString : String -> Decoder DateOnly
2526
decodeIsoString str =
2627
case fromIsoString str of
27-
Just date ->
28+
Result.Ok date ->
2829
Decode.succeed date
2930

30-
Nothing ->
31-
Decode.fail <|
32-
"Cannot convert "
33-
++ str
34-
++ " to DateOnly"
31+
Result.Err msg ->
32+
Decode.fail msg

modules/openapi-generator/src/main/resources/elm/DateTime.mustache

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Date
44
import Date.Extra exposing (fromIsoString, toIsoString)
55
import Json.Decode as Decode exposing (Decoder)
66
import Json.Encode as Encode
7+
import Result
78

89

910
type alias DateTime =
@@ -24,11 +25,8 @@ dateTimeEncoder model =
2425
decodeIsoString : String -> Decoder DateTime
2526
decodeIsoString str =
2627
case fromIsoString str of
27-
Just date ->
28+
Result.Ok date ->
2829
Decode.succeed date
2930

30-
Nothing ->
31-
Decode.fail <|
32-
"Cannot convert "
33-
++ str
34-
++ " to DateTime"
31+
Result.Err msg ->
32+
Decode.fail msg
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{{classVarName}}Decoder : Decoder {{classname}}
22
{{classVarName}}Decoder =
33
decode {{classname}}
4-
{{#allVars}}{{^discriminatorValue}} |> {{>fieldDecoder}}
5-
{{/discriminatorValue}}{{/allVars}}
4+
{{#allVars}}
5+
{{^discriminatorValue}} |> {{>fieldDecoder}}
6+
{{/discriminatorValue}}
7+
{{/allVars}}

modules/openapi-generator/src/main/resources/elm/api.mustache

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import Json.Decode as Decode
1010
basePath : String
1111
basePath =
1212
"{{basePath}}"
13-
14-
1513
{{#operations}}
1614
{{#operation}}
17-
{-
18-
{{notes}}
15+
16+
17+
{{#notes}}
18+
{-| {{{notes}}}
1919
-}
20+
{{/notes}}
2021
{{operationId}} : {{#pathParams}}{{dataType}} -> {{/pathParams}}{{#bodyParam}}{{dataType}} -> {{/bodyParam}}Http.Request {{^responses}}(){{/responses}}{{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isMapContainer}}(Dict.Dict String {{/isMapContainer}}{{#isListContainer}}(List {{/isListContainer}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/-first}}{{/responses}}
2122
{{operationId}} {{#pathParams}}{{paramName}} {{/pathParams}}{{#bodyParam}}model {{/bodyParam}}=
2223
{ method = "{{httpMethod}}"
@@ -28,7 +29,5 @@ basePath =
2829
, withCredentials = False
2930
}
3031
|> Http.request
31-
32-
3332
{{/operation}}
3433
{{/operations}}

modules/openapi-generator/src/main/resources/elm/elm-package.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"elm-lang/core": "5.1.1 <= v < 6.0.0",
1313
"elm-lang/html": "2.0.0 <= v < 3.0.0",
1414
"elm-lang/http": "1.0.0 <= v < 2.0.0",
15-
"justinmimbs/elm-date-extra": "2.0.3 <= v < 3.0.0"
15+
"justinmimbs/elm-date-extra": "3.0.0 <= v < 4.0.0"
1616
},
1717
"elm-version": "0.18.0 <= v < 0.19.0"
1818
}

modules/openapi-generator/src/main/resources/elm/licenseInfo.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
{{{appName}}}
33
{{{appDescription}}}
44

5-
{{#version}}OpenAPI spec version: {{{version}}}{{/version}}
6-
{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
5+
{{#version}}
6+
OpenAPI spec version: {{{version}}}
7+
{{/version}}
8+
{{#infoEmail}}
9+
Contact: {{{infoEmail}}}
10+
{{/infoEmail}}
711

812
NOTE: This file is auto generated by the openapi-generator.
913
https://github.com/openapitools/openapi-generator.git

modules/openapi-generator/src/main/resources/elm/model.mustache

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChil
66
import Json.Decode.Pipeline exposing (decode, optional, required)
77
import Json.Encode as Encode
88
import Maybe exposing (map, withDefault)
9-
10-
119
{{#models}}
1210
{{#model}}
11+
12+
1313
{{#description}}
14-
{-
15-
{{{description}}}
14+
{-| {{{description}}}
1615
-}
1716
{{/description}}
1817
{{#isEnum}}{{>modelTypeUnion}}{{/isEnum}}{{^isEnum}}{{#hasChildren}}{{>modelTypeDiscriminator}}{{/hasChildren}}{{^hasChildren}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{#isArrayModel}}{{>modelTypeArray}}{{/isArrayModel}}{{^isArrayModel}}{{>modelTypeAlias}}{{/isArrayModel}}{{/isAlias}}{{/hasChildren}}{{/isEnum}}
1918
{{/model}}
20-
{{^-last}}
21-
22-
23-
{{/-last}}
2419
{{/models}}

modules/openapi-generator/src/main/resources/elm/modelTypeAlias.mustache

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
2-
31
type alias {{classname}} =
4-
{ {{#vars}}{{^-first}} , {{/-first}}{{name}} : {{^required}}Maybe {{/required}}{{#isContainer}}(List {{/isContainer}}{{#isEnum}}{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{#isContainer}}){{/isContainer}}
2+
{ {{#vars}}{{^-first}} , {{/-first}}{{name}} : {{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{#isContainer}}List {{/isContainer}}{{#isEnum}}{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{^required}}{{#isContainer}}){{/isContainer}}{{/required}}
53
{{/vars}} }
64
{{#vars}}
75
{{#isEnum}}
@@ -25,4 +23,4 @@ type alias {{classname}} =
2523

2624
{{>unionEncoder}}
2725
{{/isEnum}}
28-
{{/vars}}
26+
{{/vars}}

modules/openapi-generator/src/main/resources/elm/modelTypePrimitive.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
type alias {{classname}}
42
= {{dataType}}
53

@@ -11,4 +9,4 @@ type alias {{classname}}
119

1210
{{classVarName}}Encoder : {{classname}} -> Encode.Value
1311
{{classVarName}}Encoder =
14-
{{vendorExtensions.x-encoder}}
12+
{{vendorExtensions.x-encoder}}

0 commit comments

Comments
 (0)