forked from loafle/openapi-generator-original
[haskell-http-client] update samples (OAS3) (#381)
This commit is contained in:
committed by
William Cheng
parent
4fd68f0f24
commit
68780afe9d
@@ -9,7 +9,7 @@ import qualified Data.Time as TI
|
||||
import qualified Lens.Micro as L
|
||||
import qualified Network.HTTP.Client as NH
|
||||
|
||||
import qualified SwaggerPetstore as S
|
||||
import qualified OpenAPIPetstore as S
|
||||
|
||||
import Data.Monoid ((<>))
|
||||
|
||||
@@ -56,7 +56,7 @@ main = do
|
||||
|
||||
-- * PET
|
||||
|
||||
runPet :: NH.Manager -> S.SwaggerPetstoreConfig -> IO ()
|
||||
runPet :: NH.Manager -> S.OpenAPIPetstoreConfig -> IO ()
|
||||
runPet mgr config = do
|
||||
|
||||
-- create the request for addPet, encoded with content-type application/json, with accept header application/json
|
||||
@@ -74,20 +74,20 @@ runPet mgr config = do
|
||||
-- content-type and accept types (mimeTypes) are valid
|
||||
|
||||
-- :i S.AddPet
|
||||
-- data S.AddPet -- Defined in ‘SwaggerPetstore.API’
|
||||
-- data S.AddPet -- Defined in ‘OpenAPIPetstore.API’
|
||||
-- instance S.Produces S.AddPet S.MimeXML
|
||||
-- -- Defined in ‘SwaggerPetstore.API’
|
||||
-- -- Defined in ‘OpenAPIPetstore.API’
|
||||
-- instance S.Produces S.AddPet S.MimeJSON
|
||||
-- -- Defined in ‘SwaggerPetstore.API’
|
||||
-- -- Defined in ‘OpenAPIPetstore.API’
|
||||
-- instance S.Consumes S.AddPet S.MimeXML
|
||||
-- -- Defined in ‘SwaggerPetstore.API’
|
||||
-- -- Defined in ‘OpenAPIPetstore.API’
|
||||
-- instance S.Consumes S.AddPet S.MimeJSON
|
||||
-- -- Defined in ‘SwaggerPetstore.API’
|
||||
-- -- Defined in ‘OpenAPIPetstore.API’
|
||||
-- instance S.HasBodyParam S.AddPet S.Pet
|
||||
-- -- Defined in ‘SwaggerPetstore.API’
|
||||
-- -- Defined in ‘OpenAPIPetstore.API’
|
||||
|
||||
|
||||
-- since this swagger definition has no response schema defined for
|
||||
-- since this openapi definition has no response schema defined for
|
||||
-- the 'addPet' response, we decode the response bytestring manually
|
||||
case A.eitherDecode (NH.responseBody addPetResponse) of
|
||||
Right pet@S.Pet { S.petId = Just pid } -> do
|
||||
@@ -125,9 +125,9 @@ runPet mgr config = do
|
||||
-- requred parameters are included as function arguments, optional parameters are included with applyOptionalParam
|
||||
-- inspect the UpdatePetWithForm type to see typeclasses indicating optional paramteters (:i S.UpdatePetWithForm)
|
||||
-- instance S.HasOptionalParam S.UpdatePetWithForm S.Name
|
||||
-- -- Defined in ‘SwaggerPetstore.API’
|
||||
-- -- Defined in ‘OpenAPIPetstore.API’
|
||||
-- instance S.HasOptionalParam S.UpdatePetWithForm S.Status
|
||||
-- -- Defined in ‘SwaggerPetstore.API’
|
||||
-- -- Defined in ‘OpenAPIPetstore.API’
|
||||
let updatePetWithFormRequest = S.updatePetWithForm (S.PetId pid)
|
||||
`S.applyOptionalParam` S.Name2 "petName"
|
||||
`S.applyOptionalParam` S.StatusText "pending"
|
||||
@@ -156,10 +156,7 @@ runPet mgr config = do
|
||||
|
||||
-- * STORE
|
||||
|
||||
-- declare that 'placeOrder' can recieve a JSON content-type request
|
||||
instance S.Consumes S.PlaceOrder S.MimeJSON
|
||||
|
||||
runStore :: NH.Manager -> S.SwaggerPetstoreConfig -> IO ()
|
||||
runStore :: NH.Manager -> S.OpenAPIPetstoreConfig -> IO ()
|
||||
runStore mgr config = do
|
||||
|
||||
-- we can set arbitrary headers with setHeader
|
||||
@@ -170,7 +167,7 @@ runStore mgr config = do
|
||||
|
||||
-- placeOrder
|
||||
now <- TI.getCurrentTime
|
||||
let placeOrderRequest = S.placeOrder (S.ContentType S.MimeJSON) (S.Accept S.MimeJSON) (S.mkOrder { S.orderId = Just 21, S.orderQuantity = Just 210, S.orderShipDate = Just (S.DateTime now)})
|
||||
let placeOrderRequest = S.placeOrder (S.Accept S.MimeJSON) (S.mkOrder { S.orderId = Just 21, S.orderQuantity = Just 210, S.orderShipDate = Just (S.DateTime now)})
|
||||
placeOrderResult <- S.dispatchMime mgr config placeOrderRequest
|
||||
mapM_ (\r -> putStrLn $ "placeOrderResult: " <> show r) placeOrderResult
|
||||
|
||||
@@ -191,29 +188,22 @@ runStore mgr config = do
|
||||
|
||||
-- * USER
|
||||
|
||||
-- this swagger definition doesn't declare what content-type the
|
||||
-- server actually expects for these operations, so delcare it here
|
||||
instance S.Consumes S.CreateUser S.MimeJSON
|
||||
instance S.Consumes S.UpdateUser S.MimeJSON
|
||||
instance S.Consumes S.CreateUsersWithArrayInput S.MimeJSON
|
||||
instance S.Consumes S.CreateUsersWithListInput S.MimeJSON
|
||||
|
||||
runUser :: NH.Manager -> S.SwaggerPetstoreConfig -> IO ()
|
||||
runUser :: NH.Manager -> S.OpenAPIPetstoreConfig -> IO ()
|
||||
runUser mgr config = do
|
||||
|
||||
let username = "hsusername"
|
||||
-- createUser
|
||||
let user = S.mkUser { S.userId = Just 21, S.userUsername = Just username }
|
||||
let createUserRequest = S.createUser (S.ContentType S.MimeJSON) user
|
||||
let createUserRequest = S.createUser user
|
||||
_ <- S.dispatchLbs mgr config createUserRequest
|
||||
|
||||
-- can use lenses (model record names are appended L) to view or modify records
|
||||
let users = take 8 $ drop 1 $ iterate (L.over S.userUsernameL (fmap (<> "*")) . L.over S.userIdL (fmap (+ 1))) user
|
||||
let createUsersWithArrayInputRequest = S.createUsersWithArrayInput (S.ContentType S.MimeJSON) (S.User2 users)
|
||||
let createUsersWithArrayInputRequest = S.createUsersWithArrayInput (S.User2 users)
|
||||
_ <- S.dispatchLbs mgr config createUsersWithArrayInputRequest
|
||||
|
||||
-- createUsersWithArrayInput
|
||||
let createUsersWithListInputRequest = S.createUsersWithListInput (S.ContentType S.MimeJSON) (S.User2 users)
|
||||
let createUsersWithListInputRequest = S.createUsersWithListInput (S.User2 users)
|
||||
_ <- S.dispatchLbs mgr config createUsersWithListInputRequest
|
||||
|
||||
-- getUserByName
|
||||
@@ -227,7 +217,7 @@ runUser mgr config = do
|
||||
BCL.putStrLn $ "loginUser: " <> (NH.responseBody loginUserResult)
|
||||
|
||||
-- updateUser
|
||||
let updateUserRequest = S.updateUser (S.ContentType S.MimeJSON) (user { S.userEmail = Just "xyz@example.com" }) (S.Username username)
|
||||
let updateUserRequest = S.updateUser (user { S.userEmail = Just "xyz@example.com" }) (S.Username username)
|
||||
_ <- S.dispatchLbs mgr config updateUserRequest
|
||||
|
||||
-- logoutUser
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# swagger-petstore-app
|
||||
# openapi-petstore-app
|
||||
|
||||
This contains an example application which uses the auto-generated
|
||||
swagger-petstore API Client: `haskell-http-client`
|
||||
openapi-petstore API Client: `haskell-http-client`
|
||||
|
||||
This module is not auto-generated.
|
||||
|
||||
The application requires a swagger petstore server running at
|
||||
The application requires a openapi petstore server running at
|
||||
`http://0.0.0.0/v2`, or the value of the `HOST` environment variable.
|
||||
|
||||
To compile this application, the api client library bindings generated for swagger-petstore are expected to live in the parent folder.
|
||||
To compile this application, the api client library bindings generated for openapi-petstore are expected to live in the parent folder.
|
||||
|
||||
### Petstore Server
|
||||
|
||||
@@ -25,7 +25,7 @@ server (the docker branch is used here, but docker is not required)
|
||||
2. Start the petstore server (described above)
|
||||
3. To run the application:
|
||||
```
|
||||
stack --install-ghc exec swagger-petstore-app
|
||||
stack --install-ghc exec openapi-petstore-app
|
||||
```
|
||||
4. After stack installs ghc on the first run, `--install-ghc` can be omitted
|
||||
|
||||
@@ -37,7 +37,7 @@ stack --install-ghc exec swagger-petstore-app
|
||||
Example:
|
||||
|
||||
```
|
||||
HOST=http://0.0.0.0/v2 http_proxy=http://0.0.0.0:8080 stack --install-ghc exec swagger-petstore-app
|
||||
HOST=http://0.0.0.0/v2 http_proxy=http://0.0.0.0:8080 stack --install-ghc exec openapi-petstore-app
|
||||
```
|
||||
|
||||
### Source Documentation
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
******** CONFIG ********
|
||||
{ configHost = "http://0.0.0.0/v2", configUserAgent = "swagger-haskell-http-client/1.0.0", ..}
|
||||
******** Pet operations ********
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:POST 0.0.0.0/v2/pet
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (POST 0.0.0.0/v2/pet)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:GET 0.0.0.0/v2/pet/11
|
||||
getPetById: found pet: Pet {petId = Just 11, petCategory = Nothing, petName = "name", petPhotoUrls = ["url1","url2"], petTags = Just [], petStatus = Nothing}
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (GET 0.0.0.0/v2/pet/11)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:GET 0.0.0.0/v2/pet/findByStatus?status=available%2Cpending%2Csold
|
||||
findPetsByStatus: found 10 pets
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (GET 0.0.0.0/v2/pet/findByStatus?status=available%2Cpending%2Csold)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:GET 0.0.0.0/v2/pet/findByTags?tags=name%2Ctag1
|
||||
findPetsByTags: found 3 pets
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (GET 0.0.0.0/v2/pet/findByTags?tags=name%2Ctag1)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:PUT 0.0.0.0/v2/pet
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (PUT 0.0.0.0/v2/pet)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:POST 0.0.0.0/v2/pet/11
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (POST 0.0.0.0/v2/pet/11)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:POST 0.0.0.0/v2/pet/11/uploadImage
|
||||
uploadFile: ApiResponse {apiResponseCode = Just 200, apiResponseType = Just "unknown", apiResponseMessage = Just "additionalMetadata: a package.yaml file\nFile uploaded to ./package.yaml, 942 bytes"}
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (POST 0.0.0.0/v2/pet/11/uploadImage)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:DELETE 0.0.0.0/v2/pet/11
|
||||
******** Store operations ********
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (DELETE 0.0.0.0/v2/pet/11)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:GET 0.0.0.0/v2/store/inventory
|
||||
getInventoryRequest: found 3 results
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (GET 0.0.0.0/v2/store/inventory)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:POST 0.0.0.0/v2/store/order
|
||||
placeOrderResult: Order {orderId = Just 21, orderPetId = Just 0, orderQuantity = Just 210, orderShipDate = Just 2017-09-12 03:59:19.571 UTC, orderStatus = Nothing, orderComplete = Just False}
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (POST 0.0.0.0/v2/store/order)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:GET 0.0.0.0/v2/store/order/21
|
||||
getOrderById: found order: Order {orderId = Just 21, orderPetId = Just 0, orderQuantity = Just 210, orderShipDate = Just 2017-09-12 03:59:19.571 UTC, orderStatus = Nothing, orderComplete = Just False}
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (GET 0.0.0.0/v2/store/order/21)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:DELETE 0.0.0.0/v2/store/order/21
|
||||
******** User operations ********
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (DELETE 0.0.0.0/v2/store/order/21)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:POST 0.0.0.0/v2/user
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (POST 0.0.0.0/v2/user)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:POST 0.0.0.0/v2/user/createWithArray
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (POST 0.0.0.0/v2/user/createWithArray)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:POST 0.0.0.0/v2/user/createWithList
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (POST 0.0.0.0/v2/user/createWithList)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:GET 0.0.0.0/v2/user/hsusername
|
||||
getUserByName: found user: User {userId = Just 21, userUsername = Just "hsusername", userFirstName = Nothing, userLastName = Nothing, userEmail = Nothing, userPassword = Nothing, userPhone = Nothing, userUserStatus = Just 0}
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (GET 0.0.0.0/v2/user/hsusername)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:GET 0.0.0.0/v2/user/login?password=password1&username=hsusername
|
||||
loginUser: logged in user session:1505188759581
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (GET 0.0.0.0/v2/user/login?password=password1&username=hsusername)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:PUT 0.0.0.0/v2/user/hsusername
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (PUT 0.0.0.0/v2/user/hsusername)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:GET 0.0.0.0/v2/user/logout
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (GET 0.0.0.0/v2/user/logout)
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] REQ:DELETE 0.0.0.0/v2/user/hsusername
|
||||
******** END ********
|
||||
[2017-09-12 03:59:19][SwaggerPetstore.Client][Info][kestrel][18748][ThreadId 1] RES:statusCode=200 (DELETE 0.0.0.0/v2/user/hsusername)
|
||||
@@ -2,14 +2,14 @@
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
--
|
||||
-- hash: 0a40afd0e6e2b593c40ae1588479e70d4f35af6ece13bf83bdf3c166c5ea4e7b
|
||||
-- hash: b084e6b4f90a1c0ac580f2eb3d0957a261f1db4e7309ffe2c667bc081812d93f
|
||||
|
||||
name: swagger-petstore-app
|
||||
name: openapi-petstore-app
|
||||
version: 0.1.0.0
|
||||
synopsis: Auto-generated swagger-petstore API Client
|
||||
description: Sample app for calling the swagger-petstore API based on http-client.
|
||||
synopsis: Auto-generated openapi-petstore API Client
|
||||
description: Sample app for calling the openapi-petstore API based on http-client.
|
||||
category: Web
|
||||
homepage: https://github.com/swagger-api/swagger-codegen#readme
|
||||
homepage: https://openapi-generator.tech
|
||||
author: Author Name Here
|
||||
maintainer: author.name@email.com
|
||||
copyright: YEAR - AUTHOR
|
||||
@@ -20,7 +20,7 @@ cabal-version: >= 1.10
|
||||
extra-source-files:
|
||||
README.md
|
||||
|
||||
executable swagger-petstore-app
|
||||
executable openapi-petstore-app
|
||||
main-is: Main.hs
|
||||
ghc-options: -Wall
|
||||
build-depends:
|
||||
@@ -36,12 +36,12 @@ executable swagger-petstore-app
|
||||
, http-types >=0.8 && <0.12
|
||||
, microlens >=0.4.3 && <0.5
|
||||
, mtl >=2.2.1
|
||||
, swagger-petstore
|
||||
, openapi-petstore
|
||||
, text >=0.11 && <1.3
|
||||
, time >=1.5 && <1.9
|
||||
, transformers >=0.4.0.0
|
||||
, unordered-containers
|
||||
, vector >=0.10.9 && <0.13
|
||||
other-modules:
|
||||
Paths_swagger_petstore_app
|
||||
Paths_openapi_petstore_app
|
||||
default-language: Haskell2010
|
||||
@@ -1,15 +1,15 @@
|
||||
name: swagger-petstore-app
|
||||
name: openapi-petstore-app
|
||||
version: '0.1.0.0'
|
||||
synopsis: Auto-generated swagger-petstore API Client
|
||||
synopsis: Auto-generated openapi-petstore API Client
|
||||
description: ! '
|
||||
Sample app for calling the swagger-petstore API based on http-client.
|
||||
Sample app for calling the openapi-petstore API based on http-client.
|
||||
'
|
||||
category: Web
|
||||
author: Author Name Here
|
||||
maintainer: author.name@email.com
|
||||
copyright: YEAR - AUTHOR
|
||||
license: UnspecifiedLicense
|
||||
homepage: https://github.com/swagger-api/swagger-codegen#readme
|
||||
homepage: https://openapi-generator.tech
|
||||
extra-source-files:
|
||||
- README.md
|
||||
ghc-options: -Wall
|
||||
@@ -30,8 +30,8 @@ dependencies:
|
||||
- time >=1.5 && <1.9
|
||||
- vector >=0.10.9 && <0.13
|
||||
- case-insensitive
|
||||
- swagger-petstore
|
||||
- openapi-petstore
|
||||
- microlens >= 0.4.3 && <0.5
|
||||
executables:
|
||||
swagger-petstore-app:
|
||||
openapi-petstore-app:
|
||||
main: Main.hs
|
||||
|
||||
Reference in New Issue
Block a user