[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
This commit is contained in:
Alexey Alekhin 2018-08-06 12:17:59 +02:00 committed by William Cheng
parent c116c8fb9b
commit 05db32fea2
23 changed files with 57 additions and 144 deletions

View File

@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -o samples/client/petstore/elm $@" 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 $@"
java $JAVA_OPTS -jar $executable $ags java $JAVA_OPTS -jar $executable $ags

View File

@ -4,6 +4,7 @@ import Date
import Date.Extra exposing (fromIsoString, toFormattedString) import Date.Extra exposing (fromIsoString, toFormattedString)
import Json.Decode as Decode exposing (Decoder) import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode import Json.Encode as Encode
import Result
type alias DateOnly = type alias DateOnly =
@ -24,11 +25,8 @@ dateOnlyEncoder model =
decodeIsoString : String -> Decoder DateOnly decodeIsoString : String -> Decoder DateOnly
decodeIsoString str = decodeIsoString str =
case fromIsoString str of case fromIsoString str of
Just date -> Result.Ok date ->
Decode.succeed date Decode.succeed date
Nothing -> Result.Err msg ->
Decode.fail <| Decode.fail msg
"Cannot convert "
++ str
++ " to DateOnly"

View File

@ -4,6 +4,7 @@ import Date
import Date.Extra exposing (fromIsoString, toIsoString) import Date.Extra exposing (fromIsoString, toIsoString)
import Json.Decode as Decode exposing (Decoder) import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode import Json.Encode as Encode
import Result
type alias DateTime = type alias DateTime =
@ -24,11 +25,8 @@ dateTimeEncoder model =
decodeIsoString : String -> Decoder DateTime decodeIsoString : String -> Decoder DateTime
decodeIsoString str = decodeIsoString str =
case fromIsoString str of case fromIsoString str of
Just date -> Result.Ok date ->
Decode.succeed date Decode.succeed date
Nothing -> Result.Err msg ->
Decode.fail <| Decode.fail msg
"Cannot convert "
++ str
++ " to DateTime"

View File

@ -1,5 +1,7 @@
{{classVarName}}Decoder : Decoder {{classname}} {{classVarName}}Decoder : Decoder {{classname}}
{{classVarName}}Decoder = {{classVarName}}Decoder =
decode {{classname}} decode {{classname}}
{{#allVars}}{{^discriminatorValue}} |> {{>fieldDecoder}} {{#allVars}}
{{/discriminatorValue}}{{/allVars}} {{^discriminatorValue}} |> {{>fieldDecoder}}
{{/discriminatorValue}}
{{/allVars}}

View File

@ -10,13 +10,14 @@ import Json.Decode as Decode
basePath : String basePath : String
basePath = basePath =
"{{basePath}}" "{{basePath}}"
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}
{-
{{notes}}
{{#notes}}
{-| {{{notes}}}
-} -}
{{/notes}}
{{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}} {{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}}
{{operationId}} {{#pathParams}}{{paramName}} {{/pathParams}}{{#bodyParam}}model {{/bodyParam}}= {{operationId}} {{#pathParams}}{{paramName}} {{/pathParams}}{{#bodyParam}}model {{/bodyParam}}=
{ method = "{{httpMethod}}" { method = "{{httpMethod}}"
@ -28,7 +29,5 @@ basePath =
, withCredentials = False , withCredentials = False
} }
|> Http.request |> Http.request
{{/operation}} {{/operation}}
{{/operations}} {{/operations}}

View File

@ -12,7 +12,7 @@
"elm-lang/core": "5.1.1 <= v < 6.0.0", "elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0", "elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0", "elm-lang/http": "1.0.0 <= v < 2.0.0",
"justinmimbs/elm-date-extra": "2.0.3 <= v < 3.0.0" "justinmimbs/elm-date-extra": "3.0.0 <= v < 4.0.0"
}, },
"elm-version": "0.18.0 <= v < 0.19.0" "elm-version": "0.18.0 <= v < 0.19.0"
} }

View File

@ -2,8 +2,12 @@
{{{appName}}} {{{appName}}}
{{{appDescription}}} {{{appDescription}}}
{{#version}}OpenAPI spec version: {{{version}}}{{/version}} {{#version}}
{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} OpenAPI spec version: {{{version}}}
{{/version}}
{{#infoEmail}}
Contact: {{{infoEmail}}}
{{/infoEmail}}
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git

View File

@ -6,19 +6,14 @@ module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChil
import Json.Decode.Pipeline exposing (decode, optional, required) import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode import Json.Encode as Encode
import Maybe exposing (map, withDefault) import Maybe exposing (map, withDefault)
{{#models}} {{#models}}
{{#model}} {{#model}}
{{#description}} {{#description}}
{- {-| {{{description}}}
{{{description}}}
-} -}
{{/description}} {{/description}}
{{#isEnum}}{{>modelTypeUnion}}{{/isEnum}}{{^isEnum}}{{#hasChildren}}{{>modelTypeDiscriminator}}{{/hasChildren}}{{^hasChildren}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{#isArrayModel}}{{>modelTypeArray}}{{/isArrayModel}}{{^isArrayModel}}{{>modelTypeAlias}}{{/isArrayModel}}{{/isAlias}}{{/hasChildren}}{{/isEnum}} {{#isEnum}}{{>modelTypeUnion}}{{/isEnum}}{{^isEnum}}{{#hasChildren}}{{>modelTypeDiscriminator}}{{/hasChildren}}{{^hasChildren}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{#isArrayModel}}{{>modelTypeArray}}{{/isArrayModel}}{{^isArrayModel}}{{>modelTypeAlias}}{{/isArrayModel}}{{/isAlias}}{{/hasChildren}}{{/isEnum}}
{{/model}} {{/model}}
{{^-last}}
{{/-last}}
{{/models}} {{/models}}

View File

@ -1,7 +1,5 @@
type alias {{classname}} = type alias {{classname}} =
{ {{#vars}}{{^-first}} , {{/-first}}{{name}} : {{^required}}Maybe {{/required}}{{#isContainer}}(List {{/isContainer}}{{#isEnum}}{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{#isContainer}}){{/isContainer}} { {{#vars}}{{^-first}} , {{/-first}}{{name}} : {{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{#isContainer}}List {{/isContainer}}{{#isEnum}}{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{^required}}{{#isContainer}}){{/isContainer}}{{/required}}
{{/vars}} } {{/vars}} }
{{#vars}} {{#vars}}
{{#isEnum}} {{#isEnum}}

View File

@ -1,5 +1,3 @@
type alias {{classname}} type alias {{classname}}
= {{dataType}} = {{dataType}}

View File

@ -1 +1 @@
3.0.0-SNAPSHOT 3.2.0-SNAPSHOT

View File

@ -12,7 +12,7 @@
"elm-lang/core": "5.1.1 <= v < 6.0.0", "elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0", "elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0", "elm-lang/http": "1.0.0 <= v < 2.0.0",
"justinmimbs/elm-date-extra": "2.0.3 <= v < 3.0.0" "justinmimbs/elm-date-extra": "3.0.0 <= v < 4.0.0"
}, },
"elm-version": "0.18.0 <= v < 0.19.0" "elm-version": "0.18.0 <= v < 0.19.0"
} }

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -19,11 +18,8 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault) import Maybe exposing (map, withDefault)
{- {-| Describes the result of uploading an image resource
Describes the result of uploading an image resource
-} -}
type alias ApiResponse = type alias ApiResponse =
{ code : Maybe Int { code : Maybe Int
, type_ : Maybe String , type_ : Maybe String

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -19,11 +18,8 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault) import Maybe exposing (map, withDefault)
{- {-| A category for a pet
A category for a pet
-} -}
type alias Category = type alias Category =
{ id : Maybe Int { id : Maybe Int
, name : Maybe String , name : Maybe String

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -20,11 +19,8 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault) import Maybe exposing (map, withDefault)
{- {-| An order for a pets from the pet store
An order for a pets from the pet store
-} -}
type alias Order_ = type alias Order_ =
{ id : Maybe Int { id : Maybe Int
, petId : Maybe Int , petId : Maybe Int

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -21,16 +20,13 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault) import Maybe exposing (map, withDefault)
{- {-| A pet for sale in the pet store
A pet for sale in the pet store
-} -}
type alias Pet = type alias Pet =
{ id : Maybe Int { id : Maybe Int
, category : Maybe Category , category : Maybe Category
, name : String , name : String
, photoUrls : (List String) , photoUrls : List String
, tags : Maybe (List Tag) , tags : Maybe (List Tag)
, status : Maybe Status , status : Maybe Status
} }

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -19,11 +18,8 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault) import Maybe exposing (map, withDefault)
{- {-| A tag for a pet
A tag for a pet
-} -}
type alias Tag = type alias Tag =
{ id : Maybe Int { id : Maybe Int
, name : Maybe String , name : Maybe String

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -19,11 +18,8 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault) import Maybe exposing (map, withDefault)
{- {-| A User who is purchasing from the pet store
A User who is purchasing from the pet store
-} -}
type alias User = type alias User =
{ id : Maybe Int { id : Maybe Int
, username : Maybe String , username : Maybe String

View File

@ -4,6 +4,7 @@ import Date
import Date.Extra exposing (fromIsoString, toFormattedString) import Date.Extra exposing (fromIsoString, toFormattedString)
import Json.Decode as Decode exposing (Decoder) import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode import Json.Encode as Encode
import Result
type alias DateOnly = type alias DateOnly =
@ -24,11 +25,8 @@ dateOnlyEncoder model =
decodeIsoString : String -> Decoder DateOnly decodeIsoString : String -> Decoder DateOnly
decodeIsoString str = decodeIsoString str =
case fromIsoString str of case fromIsoString str of
Just date -> Result.Ok date ->
Decode.succeed date Decode.succeed date
Nothing -> Result.Err msg ->
Decode.fail <| Decode.fail msg
"Cannot convert "
++ str
++ " to DateOnly"

View File

@ -4,6 +4,7 @@ import Date
import Date.Extra exposing (fromIsoString, toIsoString) import Date.Extra exposing (fromIsoString, toIsoString)
import Json.Decode as Decode exposing (Decoder) import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode import Json.Encode as Encode
import Result
type alias DateTime = type alias DateTime =
@ -24,11 +25,8 @@ dateTimeEncoder model =
decodeIsoString : String -> Decoder DateTime decodeIsoString : String -> Decoder DateTime
decodeIsoString str = decodeIsoString str =
case fromIsoString str of case fromIsoString str of
Just date -> Result.Ok date ->
Decode.succeed date Decode.succeed date
Nothing -> Result.Err msg ->
Decode.fail <| Decode.fail msg
"Cannot convert "
++ str
++ " to DateTime"

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -25,9 +24,6 @@ basePath =
"http://petstore.swagger.io/v2" "http://petstore.swagger.io/v2"
{-
-}
addPet : Pet -> Http.Request () addPet : Pet -> Http.Request ()
addPet model = addPet model =
{ method = "POST" { method = "POST"
@ -41,9 +37,6 @@ addPet model =
|> Http.request |> Http.request
{-
-}
deletePet : Int -> Http.Request () deletePet : Int -> Http.Request ()
deletePet petId = deletePet petId =
{ method = "DELETE" { method = "DELETE"
@ -57,8 +50,7 @@ deletePet petId =
|> Http.request |> Http.request
{- {-| Multiple status values can be provided with comma separated strings
Multiple status values can be provided with comma separated strings
-} -}
findPetsByStatus : Http.Request (List Pet) findPetsByStatus : Http.Request (List Pet)
findPetsByStatus = findPetsByStatus =
@ -73,8 +65,7 @@ findPetsByStatus =
|> Http.request |> Http.request
{- {-| Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
-} -}
findPetsByTags : Http.Request (List Pet) findPetsByTags : Http.Request (List Pet)
findPetsByTags = findPetsByTags =
@ -89,8 +80,7 @@ findPetsByTags =
|> Http.request |> Http.request
{- {-| Returns a single pet
Returns a single pet
-} -}
getPetById : Int -> Http.Request Pet getPetById : Int -> Http.Request Pet
getPetById petId = getPetById petId =
@ -105,9 +95,6 @@ getPetById petId =
|> Http.request |> Http.request
{-
-}
updatePet : Pet -> Http.Request () updatePet : Pet -> Http.Request ()
updatePet model = updatePet model =
{ method = "PUT" { method = "PUT"
@ -121,9 +108,6 @@ updatePet model =
|> Http.request |> Http.request
{-
-}
updatePetWithForm : Int -> Http.Request () updatePetWithForm : Int -> Http.Request ()
updatePetWithForm petId = updatePetWithForm petId =
{ method = "POST" { method = "POST"
@ -137,9 +121,6 @@ updatePetWithForm petId =
|> Http.request |> Http.request
{-
-}
uploadFile : Int -> Http.Request ApiResponse uploadFile : Int -> Http.Request ApiResponse
uploadFile petId = uploadFile petId =
{ method = "POST" { method = "POST"
@ -151,5 +132,3 @@ uploadFile petId =
, withCredentials = False , withCredentials = False
} }
|> Http.request |> Http.request

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -24,8 +23,7 @@ basePath =
"http://petstore.swagger.io/v2" "http://petstore.swagger.io/v2"
{- {-| For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
-} -}
deleteOrder : String -> Http.Request () deleteOrder : String -> Http.Request ()
deleteOrder orderId = deleteOrder orderId =
@ -40,8 +38,7 @@ deleteOrder orderId =
|> Http.request |> Http.request
{- {-| Returns a map of status codes to quantities
Returns a map of status codes to quantities
-} -}
getInventory : Http.Request (Dict.Dict String Int) getInventory : Http.Request (Dict.Dict String Int)
getInventory = getInventory =
@ -56,8 +53,7 @@ getInventory =
|> Http.request |> Http.request
{- {-| For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
-} -}
getOrderById : Int -> Http.Request Order_ getOrderById : Int -> Http.Request Order_
getOrderById orderId = getOrderById orderId =
@ -72,9 +68,6 @@ getOrderById orderId =
|> Http.request |> Http.request
{-
-}
placeOrder : Order_ -> Http.Request Order_ placeOrder : Order_ -> Http.Request Order_
placeOrder model = placeOrder model =
{ method = "POST" { method = "POST"
@ -86,5 +79,3 @@ placeOrder model =
, withCredentials = False , withCredentials = False
} }
|> Http.request |> Http.request

View File

@ -4,7 +4,6 @@
OpenAPI spec version: 1.0.0 OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator. NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git https://github.com/openapitools/openapi-generator.git
Do not edit this file manually. Do not edit this file manually.
@ -24,8 +23,7 @@ basePath =
"http://petstore.swagger.io/v2" "http://petstore.swagger.io/v2"
{- {-| This can only be done by the logged in user.
This can only be done by the logged in user.
-} -}
createUser : User -> Http.Request () createUser : User -> Http.Request ()
createUser model = createUser model =
@ -40,9 +38,6 @@ createUser model =
|> Http.request |> Http.request
{-
-}
createUsersWithArrayInput : User -> Http.Request () createUsersWithArrayInput : User -> Http.Request ()
createUsersWithArrayInput model = createUsersWithArrayInput model =
{ method = "POST" { method = "POST"
@ -56,9 +51,6 @@ createUsersWithArrayInput model =
|> Http.request |> Http.request
{-
-}
createUsersWithListInput : User -> Http.Request () createUsersWithListInput : User -> Http.Request ()
createUsersWithListInput model = createUsersWithListInput model =
{ method = "POST" { method = "POST"
@ -72,8 +64,7 @@ createUsersWithListInput model =
|> Http.request |> Http.request
{- {-| This can only be done by the logged in user.
This can only be done by the logged in user.
-} -}
deleteUser : String -> Http.Request () deleteUser : String -> Http.Request ()
deleteUser username = deleteUser username =
@ -88,9 +79,6 @@ deleteUser username =
|> Http.request |> Http.request
{-
-}
getUserByName : String -> Http.Request User getUserByName : String -> Http.Request User
getUserByName username = getUserByName username =
{ method = "GET" { method = "GET"
@ -104,9 +92,6 @@ getUserByName username =
|> Http.request |> Http.request
{-
-}
loginUser : Http.Request String loginUser : Http.Request String
loginUser = loginUser =
{ method = "GET" { method = "GET"
@ -120,9 +105,6 @@ loginUser =
|> Http.request |> Http.request
{-
-}
logoutUser : Http.Request () logoutUser : Http.Request ()
logoutUser = logoutUser =
{ method = "GET" { method = "GET"
@ -136,8 +118,7 @@ logoutUser =
|> Http.request |> Http.request
{- {-| This can only be done by the logged in user.
This can only be done by the logged in user.
-} -}
updateUser : String -> User -> Http.Request () updateUser : String -> User -> Http.Request ()
updateUser username model = updateUser username model =
@ -150,5 +131,3 @@ updateUser username model =
, withCredentials = False , withCredentials = False
} }
|> Http.request |> Http.request