[haskell-http-client] add support for auth methods (#6622)

* add support for auth methods

* use newtypes for required params

* fix duplicate operationId issues

* prevent aliasing of vendorextension references in fromOperation

* add --fast to stack ci build
This commit is contained in:
Jon Schoning
2017-10-07 04:12:48 -05:00
committed by wing328
parent 0db4b32384
commit 5b32e886f4
47 changed files with 4923 additions and 4097 deletions

View File

@@ -12,16 +12,17 @@
Module : SwaggerPetstore.API
-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-binds -fno-warn-unused-imports #-}
module SwaggerPetstore.API where
@@ -40,6 +41,7 @@ import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy.Char8 as BCL
import qualified Data.ByteString.Base64 as B64
import qualified Network.HTTP.Client.MultipartFormData as NH
import qualified Network.HTTP.Media as ME
@@ -49,7 +51,7 @@ import qualified Web.HttpApiData as WH
import qualified Web.FormUrlEncoded as WH
import qualified Data.CaseInsensitive as CI
import qualified Data.Data as P (Typeable)
import qualified Data.Data as P (Typeable, TypeRep, typeOf, typeRep)
import qualified Data.Foldable as P
import qualified Data.Map as Map
import qualified Data.Set as Set
@@ -217,76 +219,77 @@ instance Produces TestClientModel MimeJSON
--
-- Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
--
-- AuthMethod: http_basic_test
-- AuthMethod: 'AuthBasicHttpBasicTest'
--
-- Note: Has 'Produces' instances, but no response schema
--
testEndpointParameters
:: (Consumes TestEndpointParameters contentType)
=> contentType -- ^ request content-type ('MimeType')
-> Double -- ^ "number" - None
-> Double -- ^ "double" - None
-> Text -- ^ "patternWithoutDelimiter" - None
-> ByteArray -- ^ "byte" - None
-> Number -- ^ "number" - None
-> ParamDouble -- ^ "double" - None
-> PatternWithoutDelimiter -- ^ "patternWithoutDelimiter" - None
-> Byte -- ^ "byte" - None
-> SwaggerPetstoreRequest TestEndpointParameters contentType res
testEndpointParameters _ number double patternWithoutDelimiter byte =
testEndpointParameters _ (Number number) (ParamDouble double) (PatternWithoutDelimiter patternWithoutDelimiter) (Byte byte) =
_mkRequest "POST" ["/fake"]
`_addForm` toForm ("number", number)
`_addForm` toForm ("double", double)
`_addForm` toForm ("pattern_without_delimiter", patternWithoutDelimiter)
`_addForm` toForm ("byte", byte)
`addForm` toForm ("number", number)
`addForm` toForm ("double", double)
`addForm` toForm ("pattern_without_delimiter", patternWithoutDelimiter)
`addForm` toForm ("byte", byte)
`_hasAuthType` (P.Proxy :: P.Proxy AuthBasicHttpBasicTest)
data TestEndpointParameters
-- | /Optional Param/ "integer" - None
instance HasOptionalParam TestEndpointParameters ParamInteger where
applyOptionalParam req (ParamInteger xs) =
req `_addForm` toForm ("integer", xs)
req `addForm` toForm ("integer", xs)
-- | /Optional Param/ "int32" - None
instance HasOptionalParam TestEndpointParameters Int32 where
applyOptionalParam req (Int32 xs) =
req `_addForm` toForm ("int32", xs)
req `addForm` toForm ("int32", xs)
-- | /Optional Param/ "int64" - None
instance HasOptionalParam TestEndpointParameters Int64 where
applyOptionalParam req (Int64 xs) =
req `_addForm` toForm ("int64", xs)
req `addForm` toForm ("int64", xs)
-- | /Optional Param/ "float" - None
instance HasOptionalParam TestEndpointParameters ParamFloat where
applyOptionalParam req (ParamFloat xs) =
req `_addForm` toForm ("float", xs)
req `addForm` toForm ("float", xs)
-- | /Optional Param/ "string" - None
instance HasOptionalParam TestEndpointParameters ParamString where
applyOptionalParam req (ParamString xs) =
req `_addForm` toForm ("string", xs)
req `addForm` toForm ("string", xs)
-- | /Optional Param/ "binary" - None
instance HasOptionalParam TestEndpointParameters ParamBinary where
applyOptionalParam req (ParamBinary xs) =
req `_addForm` toForm ("binary", xs)
req `addForm` toForm ("binary", xs)
-- | /Optional Param/ "date" - None
instance HasOptionalParam TestEndpointParameters ParamDate where
applyOptionalParam req (ParamDate xs) =
req `_addForm` toForm ("date", xs)
req `addForm` toForm ("date", xs)
-- | /Optional Param/ "dateTime" - None
instance HasOptionalParam TestEndpointParameters ParamDateTime where
applyOptionalParam req (ParamDateTime xs) =
req `_addForm` toForm ("dateTime", xs)
req `addForm` toForm ("dateTime", xs)
-- | /Optional Param/ "password" - None
instance HasOptionalParam TestEndpointParameters Password where
applyOptionalParam req (Password xs) =
req `_addForm` toForm ("password", xs)
req `addForm` toForm ("password", xs)
-- | /Optional Param/ "callback" - None
instance HasOptionalParam TestEndpointParameters Callback where
applyOptionalParam req (Callback xs) =
req `_addForm` toForm ("callback", xs)
req `addForm` toForm ("callback", xs)
-- | @application/xml; charset=utf-8@
instance Consumes TestEndpointParameters MimeXmlCharsetutf8
@@ -321,12 +324,12 @@ data TestEnumParameters
-- | /Optional Param/ "enum_form_string_array" - Form parameter enum test (string array)
instance HasOptionalParam TestEnumParameters EnumFormStringArray where
applyOptionalParam req (EnumFormStringArray xs) =
req `_addForm` toFormColl CommaSeparated ("enum_form_string_array", xs)
req `addForm` toFormColl CommaSeparated ("enum_form_string_array", xs)
-- | /Optional Param/ "enum_form_string" - Form parameter enum test (string)
instance HasOptionalParam TestEnumParameters EnumFormString where
applyOptionalParam req (EnumFormString xs) =
req `_addForm` toForm ("enum_form_string", xs)
req `addForm` toForm ("enum_form_string", xs)
-- | /Optional Param/ "enum_header_string_array" - Header parameter enum test (string array)
instance HasOptionalParam TestEnumParameters EnumHeaderStringArray where
@@ -341,22 +344,22 @@ instance HasOptionalParam TestEnumParameters EnumHeaderString where
-- | /Optional Param/ "enum_query_string_array" - Query parameter enum test (string array)
instance HasOptionalParam TestEnumParameters EnumQueryStringArray where
applyOptionalParam req (EnumQueryStringArray xs) =
req `_setQuery` toQueryColl CommaSeparated ("enum_query_string_array", Just xs)
req `setQuery` toQueryColl CommaSeparated ("enum_query_string_array", Just xs)
-- | /Optional Param/ "enum_query_string" - Query parameter enum test (string)
instance HasOptionalParam TestEnumParameters EnumQueryString where
applyOptionalParam req (EnumQueryString xs) =
req `_setQuery` toQuery ("enum_query_string", Just xs)
req `setQuery` toQuery ("enum_query_string", Just xs)
-- | /Optional Param/ "enum_query_integer" - Query parameter enum test (double)
instance HasOptionalParam TestEnumParameters EnumQueryInteger where
applyOptionalParam req (EnumQueryInteger xs) =
req `_setQuery` toQuery ("enum_query_integer", Just xs)
req `setQuery` toQuery ("enum_query_integer", Just xs)
-- | /Optional Param/ "enum_query_double" - Query parameter enum test (double)
instance HasOptionalParam TestEnumParameters EnumQueryDouble where
applyOptionalParam req (EnumQueryDouble xs) =
req `_addForm` toForm ("enum_query_double", xs)
req `addForm` toForm ("enum_query_double", xs)
-- | @*/*@
instance Consumes TestEnumParameters MimeAny
@@ -376,13 +379,13 @@ instance Produces TestEnumParameters MimeAny
testJsonFormData
:: (Consumes TestJsonFormData contentType)
=> contentType -- ^ request content-type ('MimeType')
-> Text -- ^ "param" - field1
-> Text -- ^ "param2" - field2
-> Param -- ^ "param" - field1
-> Param2 -- ^ "param2" - field2
-> SwaggerPetstoreRequest TestJsonFormData contentType NoContent
testJsonFormData _ param param2 =
testJsonFormData _ (Param param) (Param2 param2) =
_mkRequest "GET" ["/fake/jsonFormData"]
`_addForm` toForm ("param", param)
`_addForm` toForm ("param2", param2)
`addForm` toForm ("param", param)
`addForm` toForm ("param2", param2)
data TestJsonFormData
@@ -398,7 +401,7 @@ instance Consumes TestJsonFormData MimeJSON
--
-- To test class name in snake case
--
-- AuthMethod: api_key_query
-- AuthMethod: 'AuthApiKeyApiKeyQuery'
--
testClassname
:: (Consumes TestClassname contentType, MimeRender contentType Client)
@@ -408,6 +411,7 @@ testClassname
testClassname _ body =
_mkRequest "PATCH" ["/fake_classname_test"]
`setBodyParam` body
`_hasAuthType` (P.Proxy :: P.Proxy AuthApiKeyApiKeyQuery)
data TestClassname
@@ -431,7 +435,7 @@ instance Produces TestClassname MimeJSON
--
--
--
-- AuthMethod: petstore_auth
-- AuthMethod: 'AuthOAuthPetstoreAuth'
--
-- Note: Has 'Produces' instances, but no response schema
--
@@ -443,6 +447,7 @@ addPet
addPet _ body =
_mkRequest "POST" ["/pet"]
`setBodyParam` body
`_hasAuthType` (P.Proxy :: P.Proxy AuthOAuthPetstoreAuth)
data AddPet
@@ -468,16 +473,17 @@ instance Produces AddPet MimeJSON
--
--
--
-- AuthMethod: petstore_auth
-- AuthMethod: 'AuthOAuthPetstoreAuth'
--
-- Note: Has 'Produces' instances, but no response schema
--
deletePet
:: Integer -- ^ "petId" - Pet id to delete
:: PetId -- ^ "petId" - Pet id to delete
-> SwaggerPetstoreRequest DeletePet MimeNoContent res
deletePet petId =
deletePet (PetId petId) =
_mkRequest "DELETE" ["/pet/",toPath petId]
`_hasAuthType` (P.Proxy :: P.Proxy AuthOAuthPetstoreAuth)
data DeletePet
instance HasOptionalParam DeletePet ApiKey where
@@ -497,14 +503,15 @@ instance Produces DeletePet MimeJSON
--
-- Multiple status values can be provided with comma separated strings
--
-- AuthMethod: petstore_auth
-- AuthMethod: 'AuthOAuthPetstoreAuth'
--
findPetsByStatus
:: [Text] -- ^ "status" - Status values that need to be considered for filter
:: Status -- ^ "status" - Status values that need to be considered for filter
-> SwaggerPetstoreRequest FindPetsByStatus MimeNoContent [Pet]
findPetsByStatus status =
findPetsByStatus (Status status) =
_mkRequest "GET" ["/pet/findByStatus"]
`_setQuery` toQueryColl CommaSeparated ("status", Just status)
`setQuery` toQueryColl CommaSeparated ("status", Just status)
`_hasAuthType` (P.Proxy :: P.Proxy AuthOAuthPetstoreAuth)
data FindPetsByStatus
-- | @application/xml@
@@ -521,14 +528,15 @@ instance Produces FindPetsByStatus MimeJSON
--
-- Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
--
-- AuthMethod: petstore_auth
-- AuthMethod: 'AuthOAuthPetstoreAuth'
--
findPetsByTags
:: [Text] -- ^ "tags" - Tags to filter by
:: Tags -- ^ "tags" - Tags to filter by
-> SwaggerPetstoreRequest FindPetsByTags MimeNoContent [Pet]
findPetsByTags tags =
findPetsByTags (Tags tags) =
_mkRequest "GET" ["/pet/findByTags"]
`_setQuery` toQueryColl CommaSeparated ("tags", Just tags)
`setQuery` toQueryColl CommaSeparated ("tags", Just tags)
`_hasAuthType` (P.Proxy :: P.Proxy AuthOAuthPetstoreAuth)
{-# DEPRECATED findPetsByTags "" #-}
@@ -547,14 +555,15 @@ instance Produces FindPetsByTags MimeJSON
--
-- Returns a single pet
--
-- AuthMethod: api_key
-- AuthMethod: 'AuthApiKeyApiKey'
--
getPetById
:: Integer -- ^ "petId" - ID of pet to return
:: PetId -- ^ "petId" - ID of pet to return
-> SwaggerPetstoreRequest GetPetById MimeNoContent Pet
getPetById petId =
getPetById (PetId petId) =
_mkRequest "GET" ["/pet/",toPath petId]
`_hasAuthType` (P.Proxy :: P.Proxy AuthApiKeyApiKey)
data GetPetById
-- | @application/xml@
@@ -571,7 +580,7 @@ instance Produces GetPetById MimeJSON
--
--
--
-- AuthMethod: petstore_auth
-- AuthMethod: 'AuthOAuthPetstoreAuth'
--
-- Note: Has 'Produces' instances, but no response schema
--
@@ -583,6 +592,7 @@ updatePet
updatePet _ body =
_mkRequest "PUT" ["/pet"]
`setBodyParam` body
`_hasAuthType` (P.Proxy :: P.Proxy AuthOAuthPetstoreAuth)
data UpdatePet
@@ -608,30 +618,31 @@ instance Produces UpdatePet MimeJSON
--
--
--
-- AuthMethod: petstore_auth
-- AuthMethod: 'AuthOAuthPetstoreAuth'
--
-- Note: Has 'Produces' instances, but no response schema
--
updatePetWithForm
:: (Consumes UpdatePetWithForm contentType)
=> contentType -- ^ request content-type ('MimeType')
-> Integer -- ^ "petId" - ID of pet that needs to be updated
-> PetId -- ^ "petId" - ID of pet that needs to be updated
-> SwaggerPetstoreRequest UpdatePetWithForm contentType res
updatePetWithForm _ petId =
updatePetWithForm _ (PetId petId) =
_mkRequest "POST" ["/pet/",toPath petId]
`_hasAuthType` (P.Proxy :: P.Proxy AuthOAuthPetstoreAuth)
data UpdatePetWithForm
-- | /Optional Param/ "name" - Updated name of the pet
instance HasOptionalParam UpdatePetWithForm Name2 where
applyOptionalParam req (Name2 xs) =
req `_addForm` toForm ("name", xs)
req `addForm` toForm ("name", xs)
-- | /Optional Param/ "status" - Updated status of the pet
instance HasOptionalParam UpdatePetWithForm Status where
applyOptionalParam req (Status xs) =
req `_addForm` toForm ("status", xs)
instance HasOptionalParam UpdatePetWithForm StatusText where
applyOptionalParam req (StatusText xs) =
req `addForm` toForm ("status", xs)
-- | @application/x-www-form-urlencoded@
instance Consumes UpdatePetWithForm MimeFormUrlEncoded
@@ -650,16 +661,17 @@ instance Produces UpdatePetWithForm MimeJSON
--
--
--
-- AuthMethod: petstore_auth
-- AuthMethod: 'AuthOAuthPetstoreAuth'
--
uploadFile
:: (Consumes UploadFile contentType)
=> contentType -- ^ request content-type ('MimeType')
-> Integer -- ^ "petId" - ID of pet to update
-> PetId -- ^ "petId" - ID of pet to update
-> SwaggerPetstoreRequest UploadFile contentType ApiResponse
uploadFile _ petId =
uploadFile _ (PetId petId) =
_mkRequest "POST" ["/pet/",toPath petId,"/uploadImage"]
`_hasAuthType` (P.Proxy :: P.Proxy AuthOAuthPetstoreAuth)
data UploadFile
@@ -693,9 +705,9 @@ instance Produces UploadFile MimeJSON
-- Note: Has 'Produces' instances, but no response schema
--
deleteOrder
:: Text -- ^ "orderId" - ID of the order that needs to be deleted
:: OrderIdText -- ^ "orderId" - ID of the order that needs to be deleted
-> SwaggerPetstoreRequest DeleteOrder MimeNoContent res
deleteOrder orderId =
deleteOrder (OrderIdText orderId) =
_mkRequest "DELETE" ["/store/order/",toPath orderId]
@@ -714,12 +726,13 @@ instance Produces DeleteOrder MimeJSON
--
-- Returns a map of status codes to quantities
--
-- AuthMethod: api_key
-- AuthMethod: 'AuthApiKeyApiKey'
--
getInventory
:: SwaggerPetstoreRequest GetInventory MimeNoContent ((Map.Map String Int))
getInventory =
_mkRequest "GET" ["/store/inventory"]
`_hasAuthType` (P.Proxy :: P.Proxy AuthApiKeyApiKey)
data GetInventory
-- | @application/json@
@@ -735,9 +748,9 @@ instance Produces GetInventory MimeJSON
-- For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
--
getOrderById
:: Integer -- ^ "orderId" - ID of pet that needs to be fetched
:: OrderId -- ^ "orderId" - ID of pet that needs to be fetched
-> SwaggerPetstoreRequest GetOrderById MimeNoContent Order
getOrderById orderId =
getOrderById (OrderId orderId) =
_mkRequest "GET" ["/store/order/",toPath orderId]
@@ -817,9 +830,9 @@ instance Produces CreateUser MimeJSON
-- Note: Has 'Produces' instances, but no response schema
--
createUsersWithArrayInput
:: (Consumes CreateUsersWithArrayInput contentType, MimeRender contentType [User])
:: (Consumes CreateUsersWithArrayInput contentType, MimeRender contentType Body)
=> contentType -- ^ request content-type ('MimeType')
-> [User] -- ^ "body" - List of user object
-> Body -- ^ "body" - List of user object
-> SwaggerPetstoreRequest CreateUsersWithArrayInput contentType res
createUsersWithArrayInput _ body =
_mkRequest "POST" ["/user/createWithArray"]
@@ -828,7 +841,7 @@ createUsersWithArrayInput _ body =
data CreateUsersWithArrayInput
-- | /Body Param/ "body" - List of user object
instance HasBodyParam CreateUsersWithArrayInput [User]
instance HasBodyParam CreateUsersWithArrayInput Body
-- | @application/xml@
instance Produces CreateUsersWithArrayInput MimeXML
-- | @application/json@
@@ -846,9 +859,9 @@ instance Produces CreateUsersWithArrayInput MimeJSON
-- Note: Has 'Produces' instances, but no response schema
--
createUsersWithListInput
:: (Consumes CreateUsersWithListInput contentType, MimeRender contentType [User])
:: (Consumes CreateUsersWithListInput contentType, MimeRender contentType Body)
=> contentType -- ^ request content-type ('MimeType')
-> [User] -- ^ "body" - List of user object
-> Body -- ^ "body" - List of user object
-> SwaggerPetstoreRequest CreateUsersWithListInput contentType res
createUsersWithListInput _ body =
_mkRequest "POST" ["/user/createWithList"]
@@ -857,7 +870,7 @@ createUsersWithListInput _ body =
data CreateUsersWithListInput
-- | /Body Param/ "body" - List of user object
instance HasBodyParam CreateUsersWithListInput [User]
instance HasBodyParam CreateUsersWithListInput Body
-- | @application/xml@
instance Produces CreateUsersWithListInput MimeXML
-- | @application/json@
@@ -875,9 +888,9 @@ instance Produces CreateUsersWithListInput MimeJSON
-- Note: Has 'Produces' instances, but no response schema
--
deleteUser
:: Text -- ^ "username" - The name that needs to be deleted
:: Username -- ^ "username" - The name that needs to be deleted
-> SwaggerPetstoreRequest DeleteUser MimeNoContent res
deleteUser username =
deleteUser (Username username) =
_mkRequest "DELETE" ["/user/",toPath username]
@@ -897,9 +910,9 @@ instance Produces DeleteUser MimeJSON
--
--
getUserByName
:: Text -- ^ "username" - The name that needs to be fetched. Use user1 for testing.
:: Username -- ^ "username" - The name that needs to be fetched. Use user1 for testing.
-> SwaggerPetstoreRequest GetUserByName MimeNoContent User
getUserByName username =
getUserByName (Username username) =
_mkRequest "GET" ["/user/",toPath username]
@@ -919,13 +932,13 @@ instance Produces GetUserByName MimeJSON
--
--
loginUser
:: Text -- ^ "username" - The user name for login
-> Text -- ^ "password" - The password for login in clear text
:: Username -- ^ "username" - The user name for login
-> Password -- ^ "password" - The password for login in clear text
-> SwaggerPetstoreRequest LoginUser MimeNoContent Text
loginUser username password =
loginUser (Username username) (Password password) =
_mkRequest "GET" ["/user/login"]
`_setQuery` toQuery ("username", Just username)
`_setQuery` toQuery ("password", Just password)
`setQuery` toQuery ("username", Just username)
`setQuery` toQuery ("password", Just password)
data LoginUser
-- | @application/xml@
@@ -969,10 +982,10 @@ instance Produces LogoutUser MimeJSON
updateUser
:: (Consumes UpdateUser contentType, MimeRender contentType User)
=> contentType -- ^ request content-type ('MimeType')
-> Text -- ^ "username" - name that need to be deleted
-> Username -- ^ "username" - name that need to be deleted
-> User -- ^ "body" - Updated user object
-> SwaggerPetstoreRequest UpdateUser contentType res
updateUser _ username body =
updateUser _ (Username username) body =
_mkRequest "PUT" ["/user/",toPath username]
`setBodyParam` body
@@ -1014,64 +1027,81 @@ class HasOptionalParam req param where
infixl 2 -&-
-- * Optional Request Parameter Types
newtype BodyOuterBoolean = BodyOuterBoolean { unBodyOuterBoolean :: OuterBoolean } deriving (P.Eq, P.Show)
newtype BodyOuterComposite = BodyOuterComposite { unBodyOuterComposite :: OuterComposite } deriving (P.Eq, P.Show)
newtype Body = Body { unBody :: OuterNumber } deriving (P.Eq, P.Show)
newtype BodyOuterString = BodyOuterString { unBodyOuterString :: OuterString } deriving (P.Eq, P.Show)
newtype ParamInteger = ParamInteger { unParamInteger :: Int } deriving (P.Eq, P.Show)
newtype Int32 = Int32 { unInt32 :: Int } deriving (P.Eq, P.Show)
newtype Int64 = Int64 { unInt64 :: Integer } deriving (P.Eq, P.Show)
newtype ParamFloat = ParamFloat { unParamFloat :: Float } deriving (P.Eq, P.Show)
newtype ParamString = ParamString { unParamString :: Text } deriving (P.Eq, P.Show)
newtype ParamBinary = ParamBinary { unParamBinary :: Binary } deriving (P.Eq, P.Show)
newtype ParamDate = ParamDate { unParamDate :: Date } deriving (P.Eq, P.Show)
newtype ParamDateTime = ParamDateTime { unParamDateTime :: DateTime } deriving (P.Eq, P.Show)
newtype Password = Password { unPassword :: Text } deriving (P.Eq, P.Show)
newtype Callback = Callback { unCallback :: Text } deriving (P.Eq, P.Show)
newtype EnumFormStringArray = EnumFormStringArray { unEnumFormStringArray :: [Text] } deriving (P.Eq, P.Show)
newtype EnumFormString = EnumFormString { unEnumFormString :: Text } deriving (P.Eq, P.Show)
newtype EnumHeaderStringArray = EnumHeaderStringArray { unEnumHeaderStringArray :: [Text] } deriving (P.Eq, P.Show)
newtype EnumHeaderString = EnumHeaderString { unEnumHeaderString :: Text } deriving (P.Eq, P.Show)
newtype EnumQueryStringArray = EnumQueryStringArray { unEnumQueryStringArray :: [Text] } deriving (P.Eq, P.Show)
newtype EnumQueryString = EnumQueryString { unEnumQueryString :: Text } deriving (P.Eq, P.Show)
newtype EnumQueryInteger = EnumQueryInteger { unEnumQueryInteger :: Int } deriving (P.Eq, P.Show)
newtype EnumQueryDouble = EnumQueryDouble { unEnumQueryDouble :: Double } deriving (P.Eq, P.Show)
-- * Request Parameter Types
-- | ApiKey
newtype ApiKey = ApiKey { unApiKey :: Text } deriving (P.Eq, P.Show)
-- | StatusText
newtype StatusText = StatusText { unStatusText :: Text } deriving (P.Eq, P.Show)
-- | ParamString
newtype ParamString = ParamString { unParamString :: Text } deriving (P.Eq, P.Show)
-- | ParamInteger
newtype ParamInteger = ParamInteger { unParamInteger :: Int } deriving (P.Eq, P.Show)
-- | EnumQueryDouble
newtype EnumQueryDouble = EnumQueryDouble { unEnumQueryDouble :: Double } deriving (P.Eq, P.Show)
-- | Number
newtype Number = Number { unNumber :: Double } deriving (P.Eq, P.Show)
-- | Int32
newtype Int32 = Int32 { unInt32 :: Int } deriving (P.Eq, P.Show)
-- | ParamDate
newtype ParamDate = ParamDate { unParamDate :: Date } deriving (P.Eq, P.Show)
-- | EnumFormString
newtype EnumFormString = EnumFormString { unEnumFormString :: Text } deriving (P.Eq, P.Show)
-- | Body
newtype Body = Body { unBody :: [User] } deriving (P.Eq, P.Show, A.ToJSON)
-- | Tags
newtype Tags = Tags { unTags :: [Text] } deriving (P.Eq, P.Show)
-- | EnumQueryInteger
newtype EnumQueryInteger = EnumQueryInteger { unEnumQueryInteger :: Int } deriving (P.Eq, P.Show)
-- | ParamFloat
newtype ParamFloat = ParamFloat { unParamFloat :: Float } deriving (P.Eq, P.Show)
-- | Name2
newtype Name2 = Name2 { unName2 :: Text } deriving (P.Eq, P.Show)
newtype Status = Status { unStatus :: Text } deriving (P.Eq, P.Show)
-- | Password
newtype Password = Password { unPassword :: Text } deriving (P.Eq, P.Show)
-- | Status
newtype Status = Status { unStatus :: [Text] } deriving (P.Eq, P.Show)
-- | ParamDouble
newtype ParamDouble = ParamDouble { unParamDouble :: Double } deriving (P.Eq, P.Show)
-- | EnumHeaderString
newtype EnumHeaderString = EnumHeaderString { unEnumHeaderString :: Text } deriving (P.Eq, P.Show)
-- | Param2
newtype Param2 = Param2 { unParam2 :: Text } deriving (P.Eq, P.Show)
-- | PetId
newtype PetId = PetId { unPetId :: Integer } deriving (P.Eq, P.Show)
-- | OrderId
newtype OrderId = OrderId { unOrderId :: Integer } deriving (P.Eq, P.Show)
-- | OrderIdText
newtype OrderIdText = OrderIdText { unOrderIdText :: Text } deriving (P.Eq, P.Show)
-- | EnumQueryString
newtype EnumQueryString = EnumQueryString { unEnumQueryString :: Text } deriving (P.Eq, P.Show)
-- | ParamDateTime
newtype ParamDateTime = ParamDateTime { unParamDateTime :: DateTime } deriving (P.Eq, P.Show)
-- | EnumQueryStringArray
newtype EnumQueryStringArray = EnumQueryStringArray { unEnumQueryStringArray :: [Text] } deriving (P.Eq, P.Show)
-- | PatternWithoutDelimiter
newtype PatternWithoutDelimiter = PatternWithoutDelimiter { unPatternWithoutDelimiter :: Text } deriving (P.Eq, P.Show)
-- | Callback
newtype Callback = Callback { unCallback :: Text } deriving (P.Eq, P.Show)
-- | Username
newtype Username = Username { unUsername :: Text } deriving (P.Eq, P.Show)
-- | Int64
newtype Int64 = Int64 { unInt64 :: Integer } deriving (P.Eq, P.Show)
-- | AdditionalMetadata
newtype AdditionalMetadata = AdditionalMetadata { unAdditionalMetadata :: Text } deriving (P.Eq, P.Show)
-- | Byte
newtype Byte = Byte { unByte :: ByteArray } deriving (P.Eq, P.Show)
-- | ParamBinary
newtype ParamBinary = ParamBinary { unParamBinary :: Binary } deriving (P.Eq, P.Show)
-- | EnumFormStringArray
newtype EnumFormStringArray = EnumFormStringArray { unEnumFormStringArray :: [Text] } deriving (P.Eq, P.Show)
-- | EnumHeaderStringArray
newtype EnumHeaderStringArray = EnumHeaderStringArray { unEnumHeaderStringArray :: [Text] } deriving (P.Eq, P.Show)
-- | Param
newtype Param = Param { unParam :: Text } deriving (P.Eq, P.Show)
-- | File
newtype File = File { unFile :: FilePath } deriving (P.Eq, P.Show)
-- * SwaggerPetstoreRequest
-- | Represents a request. The "req" type variable is the request type. The "res" type variable is the response type.
@@ -1079,6 +1109,7 @@ data SwaggerPetstoreRequest req contentType res = SwaggerPetstoreRequest
{ rMethod :: NH.Method -- ^ Method of SwaggerPetstoreRequest
, rUrlPath :: [BCL.ByteString] -- ^ Endpoint of SwaggerPetstoreRequest
, rParams :: Params -- ^ params of SwaggerPetstoreRequest
, rAuthTypes :: [P.TypeRep] -- ^ types of auth methods
}
deriving (P.Show)
@@ -1097,6 +1128,11 @@ rParamsL :: Lens_' (SwaggerPetstoreRequest req contentType res) Params
rParamsL f SwaggerPetstoreRequest{..} = (\rParams -> SwaggerPetstoreRequest { rParams, ..} ) <$> f rParams
{-# INLINE rParamsL #-}
-- | 'rParams' Lens
rAuthTypesL :: Lens_' (SwaggerPetstoreRequest req contentType res) [P.TypeRep]
rAuthTypesL f SwaggerPetstoreRequest{..} = (\rAuthTypes -> SwaggerPetstoreRequest { rAuthTypes, ..} ) <$> f rAuthTypes
{-# INLINE rAuthTypesL #-}
-- | Request Params
data Params = Params
{ paramsQuery :: NH.Query
@@ -1134,7 +1170,7 @@ data ParamBody
_mkRequest :: NH.Method -- ^ Method
-> [BCL.ByteString] -- ^ Endpoint
-> SwaggerPetstoreRequest req contentType res -- ^ req: Request Type, res: Response Type
_mkRequest m u = SwaggerPetstoreRequest m u _mkParams
_mkRequest m u = SwaggerPetstoreRequest m u _mkParams []
_mkParams :: Params
_mkParams = Params [] [] ParamBodyNone
@@ -1166,8 +1202,8 @@ _setAcceptHeader req accept =
Just m -> req `setHeader` [("accept", BC.pack $ P.show m)]
Nothing -> req `removeHeader` ["accept"]
_setQuery :: SwaggerPetstoreRequest req contentType res -> [NH.QueryItem] -> SwaggerPetstoreRequest req contentType res
_setQuery req query =
setQuery :: SwaggerPetstoreRequest req contentType res -> [NH.QueryItem] -> SwaggerPetstoreRequest req contentType res
setQuery req query =
req &
L.over
(rParamsL . paramsQueryL)
@@ -1175,8 +1211,8 @@ _setQuery req query =
where
cifst = CI.mk . P.fst
_addForm :: SwaggerPetstoreRequest req contentType res -> WH.Form -> SwaggerPetstoreRequest req contentType res
_addForm req newform =
addForm :: SwaggerPetstoreRequest req contentType res -> WH.Form -> SwaggerPetstoreRequest req contentType res
addForm req newform =
let form = case paramsBody (rParams req) of
ParamBodyFormUrlEncoded _form -> _form
_ -> mempty
@@ -1197,6 +1233,9 @@ _setBodyLBS :: SwaggerPetstoreRequest req contentType res -> BL.ByteString -> Sw
_setBodyLBS req body =
req & L.set (rParamsL . paramsBodyL) (ParamBodyBL body)
_hasAuthType :: AuthMethod authMethod => SwaggerPetstoreRequest req contentType res -> P.Proxy authMethod -> SwaggerPetstoreRequest req contentType res
_hasAuthType req proxy =
req & L.over rAuthTypesL (P.typeRep proxy :)
-- ** Params Utils
@@ -1261,3 +1300,60 @@ _toCollA' c encode one xs = case c of
{-# INLINE expandList #-}
{-# INLINE combine #-}
-- * AuthMethods
-- | Provides a method to apply auth methods to requests
class P.Typeable a => AuthMethod a where
applyAuthMethod :: SwaggerPetstoreRequest req contentType res -> a -> SwaggerPetstoreRequest req contentType res
-- | An existential wrapper for any AuthMethod
data AnyAuthMethod = forall a. AuthMethod a => AnyAuthMethod a deriving (P.Typeable)
instance AuthMethod AnyAuthMethod where applyAuthMethod req (AnyAuthMethod a) = applyAuthMethod req a
-- ** AuthApiKeyApiKey
data AuthApiKeyApiKey =
AuthApiKeyApiKey Text -- ^ secret
deriving (P.Eq, P.Show, P.Typeable)
instance AuthMethod AuthApiKeyApiKey where
applyAuthMethod req a@(AuthApiKeyApiKey secret) =
if (P.typeOf a `P.elem` rAuthTypes req)
then req `setHeader` toHeader ("api_key", secret)
else req
-- ** AuthApiKeyApiKeyQuery
data AuthApiKeyApiKeyQuery =
AuthApiKeyApiKeyQuery Text -- ^ secret
deriving (P.Eq, P.Show, P.Typeable)
instance AuthMethod AuthApiKeyApiKeyQuery where
applyAuthMethod req a@(AuthApiKeyApiKeyQuery secret) =
if (P.typeOf a `P.elem` rAuthTypes req)
then req `setQuery` toQuery ("api_key_query", Just secret)
else req
-- ** AuthBasicHttpBasicTest
data AuthBasicHttpBasicTest =
AuthBasicHttpBasicTest B.ByteString B.ByteString -- ^ username password
deriving (P.Eq, P.Show, P.Typeable)
instance AuthMethod AuthBasicHttpBasicTest where
applyAuthMethod req a@(AuthBasicHttpBasicTest user pw) =
if (P.typeOf a `P.elem` rAuthTypes req)
then req `setHeader` toHeader ("Authorization", T.decodeUtf8 cred)
else req
where cred = BC.append "Basic " (B64.encode $ BC.concat [ user, ":", pw ])
-- ** AuthOAuthPetstoreAuth
data AuthOAuthPetstoreAuth =
AuthOAuthPetstoreAuth Text -- ^ secret
deriving (P.Eq, P.Show, P.Typeable)
instance AuthMethod AuthOAuthPetstoreAuth where
applyAuthMethod req a@(AuthOAuthPetstoreAuth secret) =
if (P.typeOf a `P.elem` rAuthTypes req)
then req `setHeader` toHeader ("Authorization", "Bearer " <> secret)
else req

View File

@@ -68,6 +68,7 @@ data SwaggerPetstoreConfig = SwaggerPetstoreConfig
, configUserAgent :: Text -- ^ user-agent supplied in the Request
, configLogExecWithContext :: LogExecWithContext -- ^ Run a block using a Logger instance
, configLogContext :: LogContext -- ^ Configures the logger
, configAuthMethods :: [AnyAuthMethod] -- ^ List of configured auth methods
}
-- | display the config
@@ -96,13 +97,21 @@ newConfig = do
, configUserAgent = "swagger-haskell-http-client/1.0.0"
, configLogExecWithContext = runDefaultLogExecWithContext
, configLogContext = logCxt
, configAuthMethods = []
}
-- | updates config use AuthMethod on matching requests
addAuthMethod :: AuthMethod auth => SwaggerPetstoreConfig -> auth -> SwaggerPetstoreConfig
addAuthMethod config@SwaggerPetstoreConfig {configAuthMethods = as} a =
config { configAuthMethods = AnyAuthMethod a : as}
-- | updates the config to use stdout logging
withStdoutLogging :: SwaggerPetstoreConfig -> IO SwaggerPetstoreConfig
withStdoutLogging p = do
logCxt <- stdoutLoggingContext (configLogContext p)
return $ p { configLogExecWithContext = stdoutLoggingExec, configLogContext = logCxt }
-- | updates the config to use stderr logging
withStderrLogging :: SwaggerPetstoreConfig -> IO SwaggerPetstoreConfig
withStderrLogging p = do
logCxt <- stderrLoggingContext (configLogContext p)
@@ -235,7 +244,9 @@ _toInitRequest
-> IO (InitRequest req contentType res accept) -- ^ initialized request
_toInitRequest config req0 accept = do
parsedReq <- NH.parseRequest $ BCL.unpack $ BCL.append (configHost config) (BCL.concat (rUrlPath req0))
let req1 = _setAcceptHeader req0 accept & _setContentTypeHeader
let req1 = _applyAuthMethods req0 config
& _setContentTypeHeader
& flip _setAcceptHeader accept
reqHeaders = ("User-Agent", WH.toHeader (configUserAgent config)) : paramsHeaders (rParams req1)
reqQuery = NH.renderQuery True (paramsQuery (rParams req1))
pReq = parsedReq { NH.method = (rMethod req1)
@@ -251,6 +262,16 @@ _toInitRequest config req0 accept = do
pure (InitRequest outReq)
-- | apply all matching AuthMethods in config to request
_applyAuthMethods
:: SwaggerPetstoreRequest req contentType res
-> SwaggerPetstoreConfig
-> SwaggerPetstoreRequest req contentType res
_applyAuthMethods req SwaggerPetstoreConfig {configAuthMethods = as} =
foldl go req as
where
go r (AnyAuthMethod a) = r `applyAuthMethod` a
-- | modify the underlying Request
modifyInitRequest :: InitRequest req contentType res accept -> (NH.Request -> NH.Request) -> InitRequest req contentType res accept
modifyInitRequest (InitRequest req) f = InitRequest (f req)

View File

@@ -61,18 +61,21 @@ import qualified Prelude as P
-- ** AdditionalPropertiesClass
-- |
-- | AdditionalPropertiesClass
data AdditionalPropertiesClass = AdditionalPropertiesClass
{ additionalPropertiesClassMapProperty :: !(Maybe (Map.Map String Text)) -- ^ "map_property"
, additionalPropertiesClassMapOfMapProperty :: !(Maybe (Map.Map String (Map.Map String Text))) -- ^ "map_of_map_property"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON AdditionalPropertiesClass
instance A.FromJSON AdditionalPropertiesClass where
parseJSON = A.withObject "AdditionalPropertiesClass" $ \o ->
AdditionalPropertiesClass
<$> (o .:? "map_property")
<*> (o .:? "map_of_map_property")
-- | ToJSON AdditionalPropertiesClass
instance A.ToJSON AdditionalPropertiesClass where
toJSON AdditionalPropertiesClass {..} =
_omitNulls
@@ -92,18 +95,21 @@ mkAdditionalPropertiesClass =
-- ** Animal
-- |
-- | Animal
data Animal = Animal
{ animalClassName :: !(Text) -- ^ /Required/ "className"
, animalColor :: !(Maybe Text) -- ^ "color"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Animal
instance A.FromJSON Animal where
parseJSON = A.withObject "Animal" $ \o ->
Animal
<$> (o .: "className")
<*> (o .:? "color")
-- | ToJSON Animal
instance A.ToJSON Animal where
toJSON Animal {..} =
_omitNulls
@@ -124,16 +130,19 @@ mkAnimal animalClassName =
-- ** AnimalFarm
-- |
-- | AnimalFarm
data AnimalFarm = AnimalFarm
{
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON AnimalFarm
instance A.FromJSON AnimalFarm where
parseJSON = A.withObject "AnimalFarm" $ \o ->
pure AnimalFarm
-- | ToJSON AnimalFarm
instance A.ToJSON AnimalFarm where
toJSON AnimalFarm =
_omitNulls
@@ -151,13 +160,15 @@ mkAnimalFarm =
-- ** ApiResponse
-- |
-- | ApiResponse
data ApiResponse = ApiResponse
{ apiResponseCode :: !(Maybe Int) -- ^ "code"
, apiResponseType :: !(Maybe Text) -- ^ "type"
, apiResponseMessage :: !(Maybe Text) -- ^ "message"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON ApiResponse
instance A.FromJSON ApiResponse where
parseJSON = A.withObject "ApiResponse" $ \o ->
ApiResponse
@@ -165,6 +176,7 @@ instance A.FromJSON ApiResponse where
<*> (o .:? "type")
<*> (o .:? "message")
-- | ToJSON ApiResponse
instance A.ToJSON ApiResponse where
toJSON ApiResponse {..} =
_omitNulls
@@ -186,16 +198,19 @@ mkApiResponse =
-- ** ArrayOfArrayOfNumberOnly
-- |
-- | ArrayOfArrayOfNumberOnly
data ArrayOfArrayOfNumberOnly = ArrayOfArrayOfNumberOnly
{ arrayOfArrayOfNumberOnlyArrayArrayNumber :: !(Maybe [[Double]]) -- ^ "ArrayArrayNumber"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON ArrayOfArrayOfNumberOnly
instance A.FromJSON ArrayOfArrayOfNumberOnly where
parseJSON = A.withObject "ArrayOfArrayOfNumberOnly" $ \o ->
ArrayOfArrayOfNumberOnly
<$> (o .:? "ArrayArrayNumber")
-- | ToJSON ArrayOfArrayOfNumberOnly
instance A.ToJSON ArrayOfArrayOfNumberOnly where
toJSON ArrayOfArrayOfNumberOnly {..} =
_omitNulls
@@ -213,16 +228,19 @@ mkArrayOfArrayOfNumberOnly =
-- ** ArrayOfNumberOnly
-- |
-- | ArrayOfNumberOnly
data ArrayOfNumberOnly = ArrayOfNumberOnly
{ arrayOfNumberOnlyArrayNumber :: !(Maybe [Double]) -- ^ "ArrayNumber"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON ArrayOfNumberOnly
instance A.FromJSON ArrayOfNumberOnly where
parseJSON = A.withObject "ArrayOfNumberOnly" $ \o ->
ArrayOfNumberOnly
<$> (o .:? "ArrayNumber")
-- | ToJSON ArrayOfNumberOnly
instance A.ToJSON ArrayOfNumberOnly where
toJSON ArrayOfNumberOnly {..} =
_omitNulls
@@ -240,13 +258,15 @@ mkArrayOfNumberOnly =
-- ** ArrayTest
-- |
-- | ArrayTest
data ArrayTest = ArrayTest
{ arrayTestArrayOfString :: !(Maybe [Text]) -- ^ "array_of_string"
, arrayTestArrayArrayOfInteger :: !(Maybe [[Integer]]) -- ^ "array_array_of_integer"
, arrayTestArrayArrayOfModel :: !(Maybe [[ReadOnlyFirst]]) -- ^ "array_array_of_model"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON ArrayTest
instance A.FromJSON ArrayTest where
parseJSON = A.withObject "ArrayTest" $ \o ->
ArrayTest
@@ -254,6 +274,7 @@ instance A.FromJSON ArrayTest where
<*> (o .:? "array_array_of_integer")
<*> (o .:? "array_array_of_model")
-- | ToJSON ArrayTest
instance A.ToJSON ArrayTest where
toJSON ArrayTest {..} =
_omitNulls
@@ -275,7 +296,7 @@ mkArrayTest =
-- ** Capitalization
-- |
-- | Capitalization
data Capitalization = Capitalization
{ capitalizationSmallCamel :: !(Maybe Text) -- ^ "smallCamel"
, capitalizationCapitalCamel :: !(Maybe Text) -- ^ "CapitalCamel"
@@ -285,6 +306,8 @@ data Capitalization = Capitalization
, capitalizationAttName :: !(Maybe Text) -- ^ "ATT_NAME" - Name of the pet
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Capitalization
instance A.FromJSON Capitalization where
parseJSON = A.withObject "Capitalization" $ \o ->
Capitalization
@@ -295,6 +318,7 @@ instance A.FromJSON Capitalization where
<*> (o .:? "SCA_ETH_Flow_Points")
<*> (o .:? "ATT_NAME")
-- | ToJSON Capitalization
instance A.ToJSON Capitalization where
toJSON Capitalization {..} =
_omitNulls
@@ -322,18 +346,21 @@ mkCapitalization =
-- ** Category
-- |
-- | Category
data Category = Category
{ categoryId :: !(Maybe Integer) -- ^ "id"
, categoryName :: !(Maybe Text) -- ^ "name"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Category
instance A.FromJSON Category where
parseJSON = A.withObject "Category" $ \o ->
Category
<$> (o .:? "id")
<*> (o .:? "name")
-- | ToJSON Category
instance A.ToJSON Category where
toJSON Category {..} =
_omitNulls
@@ -353,17 +380,20 @@ mkCategory =
-- ** ClassModel
-- |
-- | ClassModel
-- Model for testing model with \"_class\" property
data ClassModel = ClassModel
{ classModelClass :: !(Maybe Text) -- ^ "_class"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON ClassModel
instance A.FromJSON ClassModel where
parseJSON = A.withObject "ClassModel" $ \o ->
ClassModel
<$> (o .:? "_class")
-- | ToJSON ClassModel
instance A.ToJSON ClassModel where
toJSON ClassModel {..} =
_omitNulls
@@ -381,16 +411,19 @@ mkClassModel =
-- ** Client
-- |
-- | Client
data Client = Client
{ clientClient :: !(Maybe Text) -- ^ "client"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Client
instance A.FromJSON Client where
parseJSON = A.withObject "Client" $ \o ->
Client
<$> (o .:? "client")
-- | ToJSON Client
instance A.ToJSON Client where
toJSON Client {..} =
_omitNulls
@@ -408,18 +441,21 @@ mkClient =
-- ** EnumArrays
-- |
-- | EnumArrays
data EnumArrays = EnumArrays
{ enumArraysJustSymbol :: !(Maybe Text) -- ^ "just_symbol"
, enumArraysArrayEnum :: !(Maybe [Text]) -- ^ "array_enum"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON EnumArrays
instance A.FromJSON EnumArrays where
parseJSON = A.withObject "EnumArrays" $ \o ->
EnumArrays
<$> (o .:? "just_symbol")
<*> (o .:? "array_enum")
-- | ToJSON EnumArrays
instance A.ToJSON EnumArrays where
toJSON EnumArrays {..} =
_omitNulls
@@ -439,16 +475,19 @@ mkEnumArrays =
-- ** EnumClass
-- |
-- | EnumClass
data EnumClass = EnumClass
{
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON EnumClass
instance A.FromJSON EnumClass where
parseJSON = A.withObject "EnumClass" $ \o ->
pure EnumClass
-- | ToJSON EnumClass
instance A.ToJSON EnumClass where
toJSON EnumClass =
_omitNulls
@@ -466,7 +505,7 @@ mkEnumClass =
-- ** EnumTest
-- |
-- | EnumTest
data EnumTest = EnumTest
{ enumTestEnumString :: !(Maybe Text) -- ^ "enum_string"
, enumTestEnumInteger :: !(Maybe Int) -- ^ "enum_integer"
@@ -474,6 +513,8 @@ data EnumTest = EnumTest
, enumTestOuterEnum :: !(Maybe OuterEnum) -- ^ "outerEnum"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON EnumTest
instance A.FromJSON EnumTest where
parseJSON = A.withObject "EnumTest" $ \o ->
EnumTest
@@ -482,6 +523,7 @@ instance A.FromJSON EnumTest where
<*> (o .:? "enum_number")
<*> (o .:? "outerEnum")
-- | ToJSON EnumTest
instance A.ToJSON EnumTest where
toJSON EnumTest {..} =
_omitNulls
@@ -505,7 +547,7 @@ mkEnumTest =
-- ** FormatTest
-- |
-- | FormatTest
data FormatTest = FormatTest
{ formatTestInteger :: !(Maybe Int) -- ^ "integer"
, formatTestInt32 :: !(Maybe Int) -- ^ "int32"
@@ -522,6 +564,8 @@ data FormatTest = FormatTest
, formatTestPassword :: !(Text) -- ^ /Required/ "password"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON FormatTest
instance A.FromJSON FormatTest where
parseJSON = A.withObject "FormatTest" $ \o ->
FormatTest
@@ -539,6 +583,7 @@ instance A.FromJSON FormatTest where
<*> (o .:? "uuid")
<*> (o .: "password")
-- | ToJSON FormatTest
instance A.ToJSON FormatTest where
toJSON FormatTest {..} =
_omitNulls
@@ -584,18 +629,21 @@ mkFormatTest formatTestNumber formatTestByte formatTestDate formatTestPassword =
-- ** HasOnlyReadOnly
-- |
-- | HasOnlyReadOnly
data HasOnlyReadOnly = HasOnlyReadOnly
{ hasOnlyReadOnlyBar :: !(Maybe Text) -- ^ "bar"
, hasOnlyReadOnlyFoo :: !(Maybe Text) -- ^ "foo"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON HasOnlyReadOnly
instance A.FromJSON HasOnlyReadOnly where
parseJSON = A.withObject "HasOnlyReadOnly" $ \o ->
HasOnlyReadOnly
<$> (o .:? "bar")
<*> (o .:? "foo")
-- | ToJSON HasOnlyReadOnly
instance A.ToJSON HasOnlyReadOnly where
toJSON HasOnlyReadOnly {..} =
_omitNulls
@@ -615,18 +663,21 @@ mkHasOnlyReadOnly =
-- ** MapTest
-- |
-- | MapTest
data MapTest = MapTest
{ mapTestMapMapOfString :: !(Maybe (Map.Map String (Map.Map String Text))) -- ^ "map_map_of_string"
, mapTestMapOfEnumString :: !(Maybe (Map.Map String Text)) -- ^ "map_of_enum_string"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON MapTest
instance A.FromJSON MapTest where
parseJSON = A.withObject "MapTest" $ \o ->
MapTest
<$> (o .:? "map_map_of_string")
<*> (o .:? "map_of_enum_string")
-- | ToJSON MapTest
instance A.ToJSON MapTest where
toJSON MapTest {..} =
_omitNulls
@@ -646,13 +697,15 @@ mkMapTest =
-- ** MixedPropertiesAndAdditionalPropertiesClass
-- |
-- | MixedPropertiesAndAdditionalPropertiesClass
data MixedPropertiesAndAdditionalPropertiesClass = MixedPropertiesAndAdditionalPropertiesClass
{ mixedPropertiesAndAdditionalPropertiesClassUuid :: !(Maybe Text) -- ^ "uuid"
, mixedPropertiesAndAdditionalPropertiesClassDateTime :: !(Maybe DateTime) -- ^ "dateTime"
, mixedPropertiesAndAdditionalPropertiesClassMap :: !(Maybe (Map.Map String Animal)) -- ^ "map"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON MixedPropertiesAndAdditionalPropertiesClass
instance A.FromJSON MixedPropertiesAndAdditionalPropertiesClass where
parseJSON = A.withObject "MixedPropertiesAndAdditionalPropertiesClass" $ \o ->
MixedPropertiesAndAdditionalPropertiesClass
@@ -660,6 +713,7 @@ instance A.FromJSON MixedPropertiesAndAdditionalPropertiesClass where
<*> (o .:? "dateTime")
<*> (o .:? "map")
-- | ToJSON MixedPropertiesAndAdditionalPropertiesClass
instance A.ToJSON MixedPropertiesAndAdditionalPropertiesClass where
toJSON MixedPropertiesAndAdditionalPropertiesClass {..} =
_omitNulls
@@ -681,19 +735,22 @@ mkMixedPropertiesAndAdditionalPropertiesClass =
-- ** Model200Response
-- |
-- | Model200Response
-- Model for testing model name starting with number
data Model200Response = Model200Response
{ model200ResponseName :: !(Maybe Int) -- ^ "name"
, model200ResponseClass :: !(Maybe Text) -- ^ "class"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Model200Response
instance A.FromJSON Model200Response where
parseJSON = A.withObject "Model200Response" $ \o ->
Model200Response
<$> (o .:? "name")
<*> (o .:? "class")
-- | ToJSON Model200Response
instance A.ToJSON Model200Response where
toJSON Model200Response {..} =
_omitNulls
@@ -713,16 +770,19 @@ mkModel200Response =
-- ** ModelList
-- |
-- | ModelList
data ModelList = ModelList
{ modelList123List :: !(Maybe Text) -- ^ "123-list"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON ModelList
instance A.FromJSON ModelList where
parseJSON = A.withObject "ModelList" $ \o ->
ModelList
<$> (o .:? "123-list")
-- | ToJSON ModelList
instance A.ToJSON ModelList where
toJSON ModelList {..} =
_omitNulls
@@ -740,17 +800,20 @@ mkModelList =
-- ** ModelReturn
-- |
-- | ModelReturn
-- Model for testing reserved words
data ModelReturn = ModelReturn
{ modelReturnReturn :: !(Maybe Int) -- ^ "return"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON ModelReturn
instance A.FromJSON ModelReturn where
parseJSON = A.withObject "ModelReturn" $ \o ->
ModelReturn
<$> (o .:? "return")
-- | ToJSON ModelReturn
instance A.ToJSON ModelReturn where
toJSON ModelReturn {..} =
_omitNulls
@@ -768,7 +831,7 @@ mkModelReturn =
-- ** Name
-- |
-- | Name
-- Model for testing model name same as property name
data Name = Name
{ nameName :: !(Int) -- ^ /Required/ "name"
@@ -777,6 +840,8 @@ data Name = Name
, name123Number :: !(Maybe Int) -- ^ "123Number"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Name
instance A.FromJSON Name where
parseJSON = A.withObject "Name" $ \o ->
Name
@@ -785,6 +850,7 @@ instance A.FromJSON Name where
<*> (o .:? "property")
<*> (o .:? "123Number")
-- | ToJSON Name
instance A.ToJSON Name where
toJSON Name {..} =
_omitNulls
@@ -809,16 +875,19 @@ mkName nameName =
-- ** NumberOnly
-- |
-- | NumberOnly
data NumberOnly = NumberOnly
{ numberOnlyJustNumber :: !(Maybe Double) -- ^ "JustNumber"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON NumberOnly
instance A.FromJSON NumberOnly where
parseJSON = A.withObject "NumberOnly" $ \o ->
NumberOnly
<$> (o .:? "JustNumber")
-- | ToJSON NumberOnly
instance A.ToJSON NumberOnly where
toJSON NumberOnly {..} =
_omitNulls
@@ -836,7 +905,7 @@ mkNumberOnly =
-- ** Order
-- |
-- | Order
data Order = Order
{ orderId :: !(Maybe Integer) -- ^ "id"
, orderPetId :: !(Maybe Integer) -- ^ "petId"
@@ -846,6 +915,8 @@ data Order = Order
, orderComplete :: !(Maybe Bool) -- ^ "complete"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Order
instance A.FromJSON Order where
parseJSON = A.withObject "Order" $ \o ->
Order
@@ -856,6 +927,7 @@ instance A.FromJSON Order where
<*> (o .:? "status")
<*> (o .:? "complete")
-- | ToJSON Order
instance A.ToJSON Order where
toJSON Order {..} =
_omitNulls
@@ -883,16 +955,19 @@ mkOrder =
-- ** OuterBoolean
-- |
-- | OuterBoolean
data OuterBoolean = OuterBoolean
{
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON OuterBoolean
instance A.FromJSON OuterBoolean where
parseJSON = A.withObject "OuterBoolean" $ \o ->
pure OuterBoolean
-- | ToJSON OuterBoolean
instance A.ToJSON OuterBoolean where
toJSON OuterBoolean =
_omitNulls
@@ -910,13 +985,15 @@ mkOuterBoolean =
-- ** OuterComposite
-- |
-- | OuterComposite
data OuterComposite = OuterComposite
{ outerCompositeMyNumber :: !(Maybe OuterNumber) -- ^ "my_number"
, outerCompositeMyString :: !(Maybe OuterString) -- ^ "my_string"
, outerCompositeMyBoolean :: !(Maybe OuterBoolean) -- ^ "my_boolean"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON OuterComposite
instance A.FromJSON OuterComposite where
parseJSON = A.withObject "OuterComposite" $ \o ->
OuterComposite
@@ -924,6 +1001,7 @@ instance A.FromJSON OuterComposite where
<*> (o .:? "my_string")
<*> (o .:? "my_boolean")
-- | ToJSON OuterComposite
instance A.ToJSON OuterComposite where
toJSON OuterComposite {..} =
_omitNulls
@@ -945,16 +1023,19 @@ mkOuterComposite =
-- ** OuterEnum
-- |
-- | OuterEnum
data OuterEnum = OuterEnum
{
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON OuterEnum
instance A.FromJSON OuterEnum where
parseJSON = A.withObject "OuterEnum" $ \o ->
pure OuterEnum
-- | ToJSON OuterEnum
instance A.ToJSON OuterEnum where
toJSON OuterEnum =
_omitNulls
@@ -972,16 +1053,19 @@ mkOuterEnum =
-- ** OuterNumber
-- |
-- | OuterNumber
data OuterNumber = OuterNumber
{
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON OuterNumber
instance A.FromJSON OuterNumber where
parseJSON = A.withObject "OuterNumber" $ \o ->
pure OuterNumber
-- | ToJSON OuterNumber
instance A.ToJSON OuterNumber where
toJSON OuterNumber =
_omitNulls
@@ -999,16 +1083,19 @@ mkOuterNumber =
-- ** OuterString
-- |
-- | OuterString
data OuterString = OuterString
{
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON OuterString
instance A.FromJSON OuterString where
parseJSON = A.withObject "OuterString" $ \o ->
pure OuterString
-- | ToJSON OuterString
instance A.ToJSON OuterString where
toJSON OuterString =
_omitNulls
@@ -1026,7 +1113,7 @@ mkOuterString =
-- ** Pet
-- |
-- | Pet
data Pet = Pet
{ petId :: !(Maybe Integer) -- ^ "id"
, petCategory :: !(Maybe Category) -- ^ "category"
@@ -1036,6 +1123,8 @@ data Pet = Pet
, petStatus :: !(Maybe Text) -- ^ "status" - pet status in the store
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Pet
instance A.FromJSON Pet where
parseJSON = A.withObject "Pet" $ \o ->
Pet
@@ -1046,6 +1135,7 @@ instance A.FromJSON Pet where
<*> (o .:? "tags")
<*> (o .:? "status")
-- | ToJSON Pet
instance A.ToJSON Pet where
toJSON Pet {..} =
_omitNulls
@@ -1075,18 +1165,21 @@ mkPet petName petPhotoUrls =
-- ** ReadOnlyFirst
-- |
-- | ReadOnlyFirst
data ReadOnlyFirst = ReadOnlyFirst
{ readOnlyFirstBar :: !(Maybe Text) -- ^ "bar"
, readOnlyFirstBaz :: !(Maybe Text) -- ^ "baz"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON ReadOnlyFirst
instance A.FromJSON ReadOnlyFirst where
parseJSON = A.withObject "ReadOnlyFirst" $ \o ->
ReadOnlyFirst
<$> (o .:? "bar")
<*> (o .:? "baz")
-- | ToJSON ReadOnlyFirst
instance A.ToJSON ReadOnlyFirst where
toJSON ReadOnlyFirst {..} =
_omitNulls
@@ -1106,16 +1199,19 @@ mkReadOnlyFirst =
-- ** SpecialModelName
-- |
-- | SpecialModelName
data SpecialModelName = SpecialModelName
{ specialModelNameSpecialPropertyName :: !(Maybe Integer) -- ^ "$special[property.name]"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON SpecialModelName
instance A.FromJSON SpecialModelName where
parseJSON = A.withObject "SpecialModelName" $ \o ->
SpecialModelName
<$> (o .:? "$special[property.name]")
-- | ToJSON SpecialModelName
instance A.ToJSON SpecialModelName where
toJSON SpecialModelName {..} =
_omitNulls
@@ -1133,18 +1229,21 @@ mkSpecialModelName =
-- ** Tag
-- |
-- | Tag
data Tag = Tag
{ tagId :: !(Maybe Integer) -- ^ "id"
, tagName :: !(Maybe Text) -- ^ "name"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Tag
instance A.FromJSON Tag where
parseJSON = A.withObject "Tag" $ \o ->
Tag
<$> (o .:? "id")
<*> (o .:? "name")
-- | ToJSON Tag
instance A.ToJSON Tag where
toJSON Tag {..} =
_omitNulls
@@ -1164,7 +1263,7 @@ mkTag =
-- ** User
-- |
-- | User
data User = User
{ userId :: !(Maybe Integer) -- ^ "id"
, userUsername :: !(Maybe Text) -- ^ "username"
@@ -1176,6 +1275,8 @@ data User = User
, userUserStatus :: !(Maybe Int) -- ^ "userStatus" - User Status
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON User
instance A.FromJSON User where
parseJSON = A.withObject "User" $ \o ->
User
@@ -1188,6 +1289,7 @@ instance A.FromJSON User where
<*> (o .:? "phone")
<*> (o .:? "userStatus")
-- | ToJSON User
instance A.ToJSON User where
toJSON User {..} =
_omitNulls
@@ -1219,13 +1321,15 @@ mkUser =
-- ** Cat
-- |
-- | Cat
data Cat = Cat
{ catClassName :: !(Text) -- ^ /Required/ "className"
, catColor :: !(Maybe Text) -- ^ "color"
, catDeclawed :: !(Maybe Bool) -- ^ "declawed"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Cat
instance A.FromJSON Cat where
parseJSON = A.withObject "Cat" $ \o ->
Cat
@@ -1233,6 +1337,7 @@ instance A.FromJSON Cat where
<*> (o .:? "color")
<*> (o .:? "declawed")
-- | ToJSON Cat
instance A.ToJSON Cat where
toJSON Cat {..} =
_omitNulls
@@ -1255,13 +1360,15 @@ mkCat catClassName =
-- ** Dog
-- |
-- | Dog
data Dog = Dog
{ dogClassName :: !(Text) -- ^ /Required/ "className"
, dogColor :: !(Maybe Text) -- ^ "color"
, dogBreed :: !(Maybe Text) -- ^ "breed"
} deriving (P.Show,P.Eq,P.Typeable)
-- | FromJSON Dog
instance A.FromJSON Dog where
parseJSON = A.withObject "Dog" $ \o ->
Dog
@@ -1269,6 +1376,7 @@ instance A.FromJSON Dog where
<*> (o .:? "color")
<*> (o .:? "breed")
-- | ToJSON Dog
instance A.ToJSON Dog where
toJSON Dog {..} =
_omitNulls
@@ -1293,21 +1401,23 @@ mkDog dogClassName =
-- * Utils
-- | Removes Null fields. (OpenAPI-Specification 2.0 does not allow Null in JSON)
_omitNulls :: [(Text, A.Value)] -> A.Value
_omitNulls = A.object . P.filter notNull
where
notNull (_, A.Null) = False
notNull _ = True
-- | Encodes fields using WH.toQueryParam
_toFormItem :: (WH.ToHttpApiData a, Functor f) => t -> f a -> f (t, [Text])
_toFormItem name x = (name,) . (:[]) . WH.toQueryParam <$> x
-- | Collapse (Just "") to Nothing
_emptyToNothing :: Maybe String -> Maybe String
_emptyToNothing (Just "") = Nothing
_emptyToNothing x = x
{-# INLINE _emptyToNothing #-}
-- | Collapse (Just mempty) to Nothing
_memptyToNothing :: (P.Monoid a, P.Eq a) => Maybe a -> Maybe a
_memptyToNothing (Just x) | x P.== P.mempty = Nothing
_memptyToNothing x = x
@@ -1340,6 +1450,7 @@ _showDateTime =
TI.formatISO8601Millis
{-# INLINE _showDateTime #-}
-- | parse an ISO8601 date-time string
_parseISO8601 :: (TI.ParseTime t, Monad m, Alternative m) => String -> m t
_parseISO8601 t =
P.asum $