From c1371dd84d8c8f736b20026eedee951623a6446c Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Mon, 27 Nov 2017 00:23:55 +0100 Subject: [PATCH] Temporary fix for Header. (#843) servant-foreign: make foreign client Header arguments have the representation of 'Maybe' in those languages --- servant-foreign/src/Servant/Foreign/Internal.hs | 4 ++-- servant-foreign/test/Servant/ForeignSpec.hs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/servant-foreign/src/Servant/Foreign/Internal.hs b/servant-foreign/src/Servant/Foreign/Internal.hs index 3e85c25c..38357560 100644 --- a/servant-foreign/src/Servant/Foreign/Internal.hs +++ b/servant-foreign/src/Servant/Foreign/Internal.hs @@ -225,7 +225,7 @@ instance (Elem JSON list, HasForeignType lang ftype a, ReflectMethod method) method = reflectMethod (Proxy :: Proxy method) methodLC = toLower $ decodeUtf8 method -instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype api) +instance (KnownSymbol sym, HasForeignType lang ftype (Maybe a), HasForeign lang ftype api) => HasForeign lang ftype (Header sym a :> api) where type Foreign ftype (Header sym a :> api) = Foreign ftype api @@ -235,7 +235,7 @@ instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype ap hname = pack . symbolVal $ (Proxy :: Proxy sym) arg = Arg { _argName = PathSegment hname - , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy a) } + , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy (Maybe a)) } subP = Proxy :: Proxy api instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype api) diff --git a/servant-foreign/test/Servant/ForeignSpec.hs b/servant-foreign/test/Servant/ForeignSpec.hs index 3bc572a5..2d093563 100644 --- a/servant-foreign/test/Servant/ForeignSpec.hs +++ b/servant-foreign/test/Servant/ForeignSpec.hs @@ -51,6 +51,9 @@ instance OVERLAPPING_ HasForeignType LangX String String where instance OVERLAPPABLE_ HasForeignType LangX String a => HasForeignType LangX String [a] where typeFor lang ftype _ = "listX of " <> typeFor lang ftype (Proxy :: Proxy a) +instance (HasForeignType LangX String a) => HasForeignType LangX String (Maybe a) where + typeFor lang ftype _ = "maybe " <> typeFor lang ftype (Proxy :: Proxy a) + type TestApi = "test" :> Header "header" [String] :> QueryFlag "flag" :> Get '[JSON] Int :<|> "test" :> QueryParam "param" Int :> ReqBody '[JSON] [String] :> Post '[JSON] NoContent @@ -75,7 +78,7 @@ listFromAPISpec = describe "listFromAPI" $ do [ Segment $ Static "test" ] [ QueryArg (Arg "flag" "boolX") Flag ] , _reqMethod = "GET" - , _reqHeaders = [HeaderArg $ Arg "header" "listX of stringX"] + , _reqHeaders = [HeaderArg $ Arg "header" "maybe listX of stringX"] , _reqBody = Nothing , _reqReturnType = Just "intX" , _reqFuncName = FunctionName ["get", "test"]