update elm petstore samples

This commit is contained in:
William Cheng 2018-11-24 19:12:22 +08:00
parent 7db12aa4af
commit 2146081ffb
22 changed files with 234 additions and 158 deletions

View File

@ -1,5 +1 @@
<<<<<<< HEAD
4.0.0-SNAPSHOT
=======
3.3.4-SNAPSHOT
>>>>>>> origin

View File

@ -21,9 +21,9 @@ import Json.Encode as Encode
{-| Describes the result of uploading an image resource
-}
type alias ApiResponse =
{ code : Maybe Int
, type_ : Maybe String
, message : Maybe String
{ code : Maybe (Int)
, type_ : Maybe (String)
, message : Maybe (String)
}
@ -35,10 +35,14 @@ decoder =
|> optional "message" (Decode.nullable Decode.string) Nothing
encoder : ApiResponse -> Encode.Value
encoder model =
Encode.object
[ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) )
, ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) )
, ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) )
]

View File

@ -21,8 +21,8 @@ import Json.Encode as Encode
{-| A category for a pet
-}
type alias Category =
{ id : Maybe Int
, name : Maybe String
{ id : Maybe (Int)
, name : Maybe (String)
}
@ -33,9 +33,13 @@ decoder =
|> optional "name" (Decode.nullable Decode.string) Nothing
encoder : Category -> Encode.Value
encoder model =
Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
]

View File

@ -22,12 +22,12 @@ import Json.Encode as Encode
{-| An order for a pets from the pet store
-}
type alias Order_ =
{ id : Maybe Int
, petId : Maybe Int
, quantity : Maybe Int
, shipDate : Maybe DateTime
, status : Maybe Status
, complete : Maybe Bool
{ id : Maybe (Int)
, petId : Maybe (Int)
, quantity : Maybe (Int)
, shipDate : Maybe (DateTime)
, status : Maybe (Status)
, complete : Maybe (Bool)
}
@ -37,6 +37,7 @@ type Status
| Delivered
decoder : Decoder Order_
decoder =
decode Order_
@ -48,6 +49,7 @@ decoder =
|> optional "complete" (Decode.nullable Decode.bool) (Just False)
encoder : Order_ -> Encode.Value
encoder model =
Encode.object
@ -57,9 +59,11 @@ encoder model =
, ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encoder model.shipDate) )
, ( "status", Maybe.withDefault Encode.null (Maybe.map statusEncoder model.status) )
, ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) )
]
statusDecoder : Decoder Status
statusDecoder =
Decode.string
@ -80,6 +84,7 @@ statusDecoder =
)
statusEncoder : Status -> Encode.Value
statusEncoder model =
case model of
@ -91,3 +96,6 @@ statusEncoder model =
Delivered ->
Encode.string "delivered"

View File

@ -23,12 +23,12 @@ import Json.Encode as Encode
{-| A pet for sale in the pet store
-}
type alias Pet =
{ id : Maybe Int
, category : Maybe Category
{ id : Maybe (Int)
, category : Maybe (Category)
, name : String
, photoUrls : List String
, tags : Maybe (List Tag)
, status : Maybe Status
, photoUrls : (List String)
, tags : Maybe ((List Tag))
, status : Maybe (Status)
}
@ -38,6 +38,7 @@ type Status
| Sold
decoder : Decoder Pet
decoder =
decode Pet
@ -49,6 +50,7 @@ decoder =
|> optional "status" (Decode.nullable statusDecoder) Nothing
encoder : Pet -> Encode.Value
encoder model =
Encode.object
@ -58,9 +60,11 @@ encoder model =
, ( "photoUrls", (Encode.list << List.map Encode.string) model.photoUrls )
, ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list << List.map Tag.encoder) model.tags) )
, ( "status", Maybe.withDefault Encode.null (Maybe.map statusEncoder model.status) )
]
statusDecoder : Decoder Status
statusDecoder =
Decode.string
@ -81,6 +85,7 @@ statusDecoder =
)
statusEncoder : Status -> Encode.Value
statusEncoder model =
case model of
@ -92,3 +97,6 @@ statusEncoder model =
Sold ->
Encode.string "sold"

View File

@ -21,8 +21,8 @@ import Json.Encode as Encode
{-| A tag for a pet
-}
type alias Tag =
{ id : Maybe Int
, name : Maybe String
{ id : Maybe (Int)
, name : Maybe (String)
}
@ -33,9 +33,13 @@ decoder =
|> optional "name" (Decode.nullable Decode.string) Nothing
encoder : Tag -> Encode.Value
encoder model =
Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
]

View File

@ -21,14 +21,14 @@ import Json.Encode as Encode
{-| A User who is purchasing from the pet store
-}
type alias User =
{ id : Maybe Int
, username : Maybe String
, firstName : Maybe String
, lastName : Maybe String
, email : Maybe String
, password : Maybe String
, phone : Maybe String
, userStatus : Maybe Int
{ id : Maybe (Int)
, username : Maybe (String)
, firstName : Maybe (String)
, lastName : Maybe (String)
, email : Maybe (String)
, password : Maybe (String)
, phone : Maybe (String)
, userStatus : Maybe (Int)
}
@ -45,6 +45,7 @@ decoder =
|> optional "userStatus" (Decode.nullable Decode.int) Nothing
encoder : User -> Encode.Value
encoder model =
Encode.object
@ -56,4 +57,7 @@ encoder model =
, ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) )
, ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) )
, ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) )
]

View File

@ -12,8 +12,8 @@
module Request.Pet exposing (addPet, deletePet, findPetsByStatus, findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile)
import Data.ApiResponse as ApiResponse exposing (ApiResponse)
import Data.Pet as Pet exposing (Pet)
import Data.ApiResponse as ApiResponse exposing (ApiResponse)
import Dict
import Http
import Json.Decode as Decode

View File

@ -1,5 +1 @@
<<<<<<< HEAD
4.0.0-SNAPSHOT
=======
3.3.4-SNAPSHOT
>>>>>>> origin

View File

@ -21,9 +21,9 @@ import Json.Encode as Encode
{-| Describes the result of uploading an image resource
-}
type alias ApiResponse =
{ code : Maybe Int
, type_ : Maybe String
, message : Maybe String
{ code : Maybe (Int)
, type_ : Maybe (String)
, message : Maybe (String)
}
@ -35,10 +35,14 @@ decoder =
|> optional "message" (Decode.nullable Decode.string) Nothing
encoder : ApiResponse -> Encode.Value
encoder model =
Encode.object
[ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) )
, ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) )
, ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) )
]

View File

@ -21,8 +21,8 @@ import Json.Encode as Encode
{-| A category for a pet
-}
type alias Category =
{ id : Maybe Int
, name : Maybe String
{ id : Maybe (Int)
, name : Maybe (String)
}
@ -33,9 +33,13 @@ decoder =
|> optional "name" (Decode.nullable Decode.string) Nothing
encoder : Category -> Encode.Value
encoder model =
Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
]

View File

@ -22,12 +22,12 @@ import Json.Encode as Encode
{-| An order for a pets from the pet store
-}
type alias Order_ =
{ id : Maybe Int
, petId : Maybe Int
, quantity : Maybe Int
, shipDate : Maybe DateTime
, status : Maybe Status
, complete : Maybe Bool
{ id : Maybe (Int)
, petId : Maybe (Int)
, quantity : Maybe (Int)
, shipDate : Maybe (DateTime)
, status : Maybe (Status)
, complete : Maybe (Bool)
}
@ -37,6 +37,7 @@ type Status
| Delivered
decoder : Decoder Order_
decoder =
Decode.succeed Order_
@ -48,6 +49,7 @@ decoder =
|> optional "complete" (Decode.nullable Decode.bool) (Just False)
encoder : Order_ -> Encode.Value
encoder model =
Encode.object
@ -57,9 +59,11 @@ encoder model =
, ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encoder model.shipDate) )
, ( "status", Maybe.withDefault Encode.null (Maybe.map statusEncoder model.status) )
, ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) )
]
statusDecoder : Decoder Status
statusDecoder =
Decode.string
@ -80,6 +84,7 @@ statusDecoder =
)
statusEncoder : Status -> Encode.Value
statusEncoder model =
case model of
@ -91,3 +96,6 @@ statusEncoder model =
Delivered ->
Encode.string "delivered"

View File

@ -23,12 +23,12 @@ import Json.Encode as Encode
{-| A pet for sale in the pet store
-}
type alias Pet =
{ id : Maybe Int
, category : Maybe Category
{ id : Maybe (Int)
, category : Maybe (Category)
, name : String
, photoUrls : List String
, tags : Maybe (List Tag)
, status : Maybe Status
, photoUrls : (List String)
, tags : Maybe ((List Tag))
, status : Maybe (Status)
}
@ -38,6 +38,7 @@ type Status
| Sold
decoder : Decoder Pet
decoder =
Decode.succeed Pet
@ -49,18 +50,21 @@ decoder =
|> optional "status" (Decode.nullable statusDecoder) Nothing
encoder : Pet -> Encode.Value
encoder model =
Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encoder model.category) )
, ( "name", Encode.string model.name )
, ( "photoUrls", Encode.list Encode.string model.photoUrls )
, ( "photoUrls", (Encode.list Encode.string) model.photoUrls )
, ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encoder) model.tags) )
, ( "status", Maybe.withDefault Encode.null (Maybe.map statusEncoder model.status) )
]
statusDecoder : Decoder Status
statusDecoder =
Decode.string
@ -81,6 +85,7 @@ statusDecoder =
)
statusEncoder : Status -> Encode.Value
statusEncoder model =
case model of
@ -92,3 +97,6 @@ statusEncoder model =
Sold ->
Encode.string "sold"

View File

@ -21,8 +21,8 @@ import Json.Encode as Encode
{-| A tag for a pet
-}
type alias Tag =
{ id : Maybe Int
, name : Maybe String
{ id : Maybe (Int)
, name : Maybe (String)
}
@ -33,9 +33,13 @@ decoder =
|> optional "name" (Decode.nullable Decode.string) Nothing
encoder : Tag -> Encode.Value
encoder model =
Encode.object
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
]

View File

@ -21,14 +21,14 @@ import Json.Encode as Encode
{-| A User who is purchasing from the pet store
-}
type alias User =
{ id : Maybe Int
, username : Maybe String
, firstName : Maybe String
, lastName : Maybe String
, email : Maybe String
, password : Maybe String
, phone : Maybe String
, userStatus : Maybe Int
{ id : Maybe (Int)
, username : Maybe (String)
, firstName : Maybe (String)
, lastName : Maybe (String)
, email : Maybe (String)
, password : Maybe (String)
, phone : Maybe (String)
, userStatus : Maybe (Int)
}
@ -45,6 +45,7 @@ decoder =
|> optional "userStatus" (Decode.nullable Decode.int) Nothing
encoder : User -> Encode.Value
encoder model =
Encode.object
@ -56,4 +57,7 @@ encoder model =
, ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) )
, ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) )
, ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) )
]

View File

@ -12,8 +12,8 @@
module Request.Pet exposing (addPet, deletePet, findPetsByStatus, findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile)
import Data.ApiResponse as ApiResponse exposing (ApiResponse)
import Data.Pet as Pet exposing (Pet)
import Data.ApiResponse as ApiResponse exposing (ApiResponse)
import Dict
import Http
import Json.Decode as Decode
@ -28,15 +28,16 @@ basePath =
addPet :
{ onSend : Result Http.Error () -> msg
, body : Pet
}
-> Cmd msg
addPet params =
Http.request
{ method = "POST"
, headers = []
, url =
Url.crossOrigin basePath
[ "pet" ]
, url = Url.crossOrigin basePath
["pet"]
(List.filterMap identity [])
, body = Http.jsonBody <| Pet.encoder params.body
, expect = Http.expectWhatever params.onSend
@ -47,16 +48,17 @@ addPet params =
deletePet :
{ onSend : Result Http.Error () -> msg
, petId : Int
}
-> Cmd msg
deletePet params =
Http.request
{ method = "DELETE"
, headers = []
, url =
Url.crossOrigin basePath
[ "pet", String.fromInt params.petId ]
, url = Url.crossOrigin basePath
["pet", String.fromInt params.petId]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectWhatever params.onSend
@ -69,6 +71,8 @@ deletePet params =
-}
findPetsByStatus :
{ onSend : Result Http.Error (List Pet) -> msg
, status : List String
}
-> Cmd msg
@ -76,10 +80,9 @@ findPetsByStatus params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin basePath
[ "pet", "findByStatus" ]
(List.filterMap identity [ Just (Url.string "status" <| String.join "," params.status) ])
, url = Url.crossOrigin basePath
["pet", "findByStatus"]
(List.filterMap identity [Just (Url.string "status" <| String.join "," params.status)])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend (Decode.list Pet.decoder)
, timeout = Just 30000
@ -91,6 +94,8 @@ findPetsByStatus params =
-}
findPetsByTags :
{ onSend : Result Http.Error (List Pet) -> msg
, tags : List String
}
-> Cmd msg
@ -98,10 +103,9 @@ findPetsByTags params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin basePath
[ "pet", "findByTags" ]
(List.filterMap identity [ Just (Url.string "tags" <| String.join "," params.tags) ])
, url = Url.crossOrigin basePath
["pet", "findByTags"]
(List.filterMap identity [Just (Url.string "tags" <| String.join "," params.tags)])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend (Decode.list Pet.decoder)
, timeout = Just 30000
@ -113,16 +117,17 @@ findPetsByTags params =
-}
getPetById :
{ onSend : Result Http.Error Pet -> msg
, petId : Int
}
-> Cmd msg
getPetById params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin basePath
[ "pet", String.fromInt params.petId ]
, url = Url.crossOrigin basePath
["pet", String.fromInt params.petId]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend Pet.decoder
@ -134,15 +139,16 @@ getPetById params =
updatePet :
{ onSend : Result Http.Error () -> msg
, body : Pet
}
-> Cmd msg
updatePet params =
Http.request
{ method = "PUT"
, headers = []
, url =
Url.crossOrigin basePath
[ "pet" ]
, url = Url.crossOrigin basePath
["pet"]
(List.filterMap identity [])
, body = Http.jsonBody <| Pet.encoder params.body
, expect = Http.expectWhatever params.onSend
@ -153,16 +159,17 @@ updatePet params =
updatePetWithForm :
{ onSend : Result Http.Error () -> msg
, petId : Int
}
-> Cmd msg
updatePetWithForm params =
Http.request
{ method = "POST"
, headers = []
, url =
Url.crossOrigin basePath
[ "pet", String.fromInt params.petId ]
, url = Url.crossOrigin basePath
["pet", String.fromInt params.petId]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectWhatever params.onSend
@ -173,16 +180,17 @@ updatePetWithForm params =
uploadFile :
{ onSend : Result Http.Error ApiResponse -> msg
, petId : Int
}
-> Cmd msg
uploadFile params =
Http.request
{ method = "POST"
, headers = []
, url =
Url.crossOrigin basePath
[ "pet", String.fromInt params.petId, "uploadImage" ]
, url = Url.crossOrigin basePath
["pet", String.fromInt params.petId, "uploadImage"]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend ApiResponse.decoder

View File

@ -28,16 +28,17 @@ basePath =
-}
deleteOrder :
{ onSend : Result Http.Error () -> msg
, orderId : String
}
-> Cmd msg
deleteOrder params =
Http.request
{ method = "DELETE"
, headers = []
, url =
Url.crossOrigin basePath
[ "store", "order", params.orderId ]
, url = Url.crossOrigin basePath
["store", "order", params.orderId]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectWhatever params.onSend
@ -50,15 +51,17 @@ deleteOrder params =
-}
getInventory :
{ onSend : Result Http.Error (Dict.Dict String Int) -> msg
}
-> Cmd msg
getInventory params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin basePath
[ "store", "inventory" ]
, url = Url.crossOrigin basePath
["store", "inventory"]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend (Decode.dict Decode.int)
@ -71,16 +74,17 @@ getInventory params =
-}
getOrderById :
{ onSend : Result Http.Error Order_ -> msg
, orderId : Int
}
-> Cmd msg
getOrderById params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin basePath
[ "store", "order", String.fromInt params.orderId ]
, url = Url.crossOrigin basePath
["store", "order", String.fromInt params.orderId]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend Order_.decoder
@ -92,15 +96,16 @@ getOrderById params =
placeOrder :
{ onSend : Result Http.Error Order_ -> msg
, body : Order_
}
-> Cmd msg
placeOrder params =
Http.request
{ method = "POST"
, headers = []
, url =
Url.crossOrigin basePath
[ "store", "order" ]
, url = Url.crossOrigin basePath
["store", "order"]
(List.filterMap identity [])
, body = Http.jsonBody <| Order_.encoder params.body
, expect = Http.expectJson params.onSend Order_.decoder

View File

@ -29,15 +29,16 @@ basePath =
createUser :
{ onSend : Result Http.Error () -> msg
, body : User
}
-> Cmd msg
createUser params =
Http.request
{ method = "POST"
, headers = []
, url =
Url.crossOrigin basePath
[ "user" ]
, url = Url.crossOrigin basePath
["user"]
(List.filterMap identity [])
, body = Http.jsonBody <| User.encoder params.body
, expect = Http.expectWhatever params.onSend
@ -49,15 +50,16 @@ createUser params =
createUsersWithArrayInput :
{ onSend : Result Http.Error () -> msg
, body : User
}
-> Cmd msg
createUsersWithArrayInput params =
Http.request
{ method = "POST"
, headers = []
, url =
Url.crossOrigin basePath
[ "user", "createWithArray" ]
, url = Url.crossOrigin basePath
["user", "createWithArray"]
(List.filterMap identity [])
, body = Http.jsonBody <| User.encoder params.body
, expect = Http.expectWhatever params.onSend
@ -69,15 +71,16 @@ createUsersWithArrayInput params =
createUsersWithListInput :
{ onSend : Result Http.Error () -> msg
, body : User
}
-> Cmd msg
createUsersWithListInput params =
Http.request
{ method = "POST"
, headers = []
, url =
Url.crossOrigin basePath
[ "user", "createWithList" ]
, url = Url.crossOrigin basePath
["user", "createWithList"]
(List.filterMap identity [])
, body = Http.jsonBody <| User.encoder params.body
, expect = Http.expectWhatever params.onSend
@ -90,16 +93,17 @@ createUsersWithListInput params =
-}
deleteUser :
{ onSend : Result Http.Error () -> msg
, username : String
}
-> Cmd msg
deleteUser params =
Http.request
{ method = "DELETE"
, headers = []
, url =
Url.crossOrigin basePath
[ "user", params.username ]
, url = Url.crossOrigin basePath
["user", params.username]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectWhatever params.onSend
@ -110,16 +114,17 @@ deleteUser params =
getUserByName :
{ onSend : Result Http.Error User -> msg
, username : String
}
-> Cmd msg
getUserByName params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin basePath
[ "user", params.username ]
, url = Url.crossOrigin basePath
["user", params.username]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend User.decoder
@ -130,18 +135,18 @@ getUserByName params =
loginUser :
{ onSend : Result Http.Error String -> msg
, username : String
, password : String
, username : String , password : String
}
-> Cmd msg
loginUser params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin basePath
[ "user", "login" ]
(List.filterMap identity [ Just (Url.string "username" <| params.username), Just (Url.string "password" <| params.password) ])
, url = Url.crossOrigin basePath
["user", "login"]
(List.filterMap identity [Just (Url.string "username" <| params.username), Just (Url.string "password" <| params.password)])
, body = Http.emptyBody
, expect = Http.expectJson params.onSend Decode.string
, timeout = Just 30000
@ -151,15 +156,17 @@ loginUser params =
logoutUser :
{ onSend : Result Http.Error () -> msg
}
-> Cmd msg
logoutUser params =
Http.request
{ method = "GET"
, headers = []
, url =
Url.crossOrigin basePath
[ "user", "logout" ]
, url = Url.crossOrigin basePath
["user", "logout"]
(List.filterMap identity [])
, body = Http.emptyBody
, expect = Http.expectWhatever params.onSend
@ -174,15 +181,15 @@ updateUser :
{ onSend : Result Http.Error () -> msg
, body : User
, username : String
}
-> Cmd msg
updateUser params =
Http.request
{ method = "PUT"
, headers = []
, url =
Url.crossOrigin basePath
[ "user", params.username ]
, url = Url.crossOrigin basePath
["user", params.username]
(List.filterMap identity [])
, body = Http.jsonBody <| User.encoder params.body
, expect = Http.expectWhatever params.onSend