[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.
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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,7 +12,7 @@
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.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"
}

View File

@ -2,8 +2,12 @@
{{{appName}}}
{{{appDescription}}}
{{#version}}OpenAPI spec version: {{{version}}}{{/version}}
{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
{{#version}}
OpenAPI spec version: {{{version}}}
{{/version}}
{{#infoEmail}}
Contact: {{{infoEmail}}}
{{/infoEmail}}
NOTE: This file is auto generated by the openapi-generator.
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.Encode as Encode
import Maybe exposing (map, withDefault)
{{#models}}
{{#model}}
{{#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}}
{{/model}}
{{^-last}}
{{/-last}}
{{/models}}

View File

@ -1,7 +1,5 @@
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}}
{{#isEnum}}
@ -25,4 +23,4 @@ type alias {{classname}} =
{{>unionEncoder}}
{{/isEnum}}
{{/vars}}
{{/vars}}

View File

@ -1,5 +1,3 @@
type alias {{classname}}
= {{dataType}}
@ -11,4 +9,4 @@ type alias {{classname}}
{{classVarName}}Encoder : {{classname}} -> Encode.Value
{{classVarName}}Encoder =
{{vendorExtensions.x-encoder}}
{{vendorExtensions.x-encoder}}

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/html": "2.0.0 <= v < 3.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"
}

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -19,11 +18,8 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
Describes the result of uploading an image resource
{-| Describes the result of uploading an image resource
-}
type alias ApiResponse =
{ code : Maybe Int
, type_ : Maybe String

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -19,11 +18,8 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
A category for a pet
{-| A category for a pet
-}
type alias Category =
{ id : Maybe Int
, name : Maybe String

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -20,11 +19,8 @@ import Json.Encode as Encode
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_ =
{ id : Maybe Int
, petId : Maybe Int

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -21,16 +20,13 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
A pet for sale in the pet store
{-| A pet for sale in the pet store
-}
type alias Pet =
{ id : Maybe Int
, category : Maybe Category
, name : String
, photoUrls : (List String)
, photoUrls : List String
, tags : Maybe (List Tag)
, status : Maybe Status
}

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -19,11 +18,8 @@ import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
A tag for a pet
{-| A tag for a pet
-}
type alias Tag =
{ id : Maybe Int
, name : Maybe String

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -19,11 +18,8 @@ import Json.Encode as Encode
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 =
{ id : Maybe Int
, username : Maybe String

View File

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

View File

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

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -25,9 +24,6 @@ basePath =
"http://petstore.swagger.io/v2"
{-
-}
addPet : Pet -> Http.Request ()
addPet model =
{ method = "POST"
@ -41,9 +37,6 @@ addPet model =
|> Http.request
{-
-}
deletePet : Int -> Http.Request ()
deletePet petId =
{ method = "DELETE"
@ -57,8 +50,7 @@ deletePet petId =
|> 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 =
@ -73,8 +65,7 @@ findPetsByStatus =
|> 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 =
@ -89,8 +80,7 @@ findPetsByTags =
|> Http.request
{-
Returns a single pet
{-| Returns a single pet
-}
getPetById : Int -> Http.Request Pet
getPetById petId =
@ -105,9 +95,6 @@ getPetById petId =
|> Http.request
{-
-}
updatePet : Pet -> Http.Request ()
updatePet model =
{ method = "PUT"
@ -121,9 +108,6 @@ updatePet model =
|> Http.request
{-
-}
updatePetWithForm : Int -> Http.Request ()
updatePetWithForm petId =
{ method = "POST"
@ -137,9 +121,6 @@ updatePetWithForm petId =
|> Http.request
{-
-}
uploadFile : Int -> Http.Request ApiResponse
uploadFile petId =
{ method = "POST"
@ -151,5 +132,3 @@ uploadFile petId =
, withCredentials = False
}
|> Http.request

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -24,8 +23,7 @@ basePath =
"http://petstore.swagger.io/v2"
{-
For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
{-| For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
-}
deleteOrder : String -> Http.Request ()
deleteOrder orderId =
@ -40,8 +38,7 @@ deleteOrder orderId =
|> 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 =
@ -56,8 +53,7 @@ getInventory =
|> Http.request
{-
For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
{-| For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
-}
getOrderById : Int -> Http.Request Order_
getOrderById orderId =
@ -72,9 +68,6 @@ getOrderById orderId =
|> Http.request
{-
-}
placeOrder : Order_ -> Http.Request Order_
placeOrder model =
{ method = "POST"
@ -86,5 +79,3 @@ placeOrder model =
, withCredentials = False
}
|> Http.request

View File

@ -3,7 +3,6 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
@ -24,8 +23,7 @@ basePath =
"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 model =
@ -40,9 +38,6 @@ createUser model =
|> Http.request
{-
-}
createUsersWithArrayInput : User -> Http.Request ()
createUsersWithArrayInput model =
{ method = "POST"
@ -56,9 +51,6 @@ createUsersWithArrayInput model =
|> Http.request
{-
-}
createUsersWithListInput : User -> Http.Request ()
createUsersWithListInput model =
{ method = "POST"
@ -72,8 +64,7 @@ createUsersWithListInput model =
|> 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 username =
@ -88,9 +79,6 @@ deleteUser username =
|> Http.request
{-
-}
getUserByName : String -> Http.Request User
getUserByName username =
{ method = "GET"
@ -104,9 +92,6 @@ getUserByName username =
|> Http.request
{-
-}
loginUser : Http.Request String
loginUser =
{ method = "GET"
@ -120,9 +105,6 @@ loginUser =
|> Http.request
{-
-}
logoutUser : Http.Request ()
logoutUser =
{ method = "GET"
@ -136,8 +118,7 @@ logoutUser =
|> 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 username model =
@ -150,5 +131,3 @@ updateUser username model =
, withCredentials = False
}
|> Http.request