git.iko.soy/typeable/servant
on master help sign in
Temporary fix for Header. (#843)

servant-foreign: make foreign client Header arguments have the representation of 'Maybe' in those languages

commitc1371dd84d8c8f736b20026eedee951623a6446c authorDimitri Sabadie <dimitri.sabadie@gmail.com> dateMon 27 Nov 2017, 00:23 (9 years ago) parent6321859
2 files changed+6−3
servant-foreign/src/Servant/Foreign/Internal.hs+2−2 servant-foreign/test/Servant/ForeignSpec.hs+4−1
servant-foreign/src/Servant/Foreign/Internal.hs+2−2
@@ -225,7 +225,7 @@ instance (Elem JSON list, HasForeignType lang ftype a, ReflectMethod method)
225225 method = reflectMethod (Proxy :: Proxy method)
226226 methodLC = toLower $ decodeUtf8 method
227227
228−instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype api)
228+instance (KnownSymbol sym, HasForeignType lang ftype (Maybe a), HasForeign lang ftype api)
229229 => HasForeign lang ftype (Header sym a :> api) where
230230 type Foreign ftype (Header sym a :> api) = Foreign ftype api
231231
@@ -235,7 +235,7 @@ instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype ap
235235 hname = pack . symbolVal $ (Proxy :: Proxy sym)
236236 arg = Arg
237237 { _argName = PathSegment hname
238− , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy a) }
238+ , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy (Maybe a)) }
239239 subP = Proxy :: Proxy api
240240
241241instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype api)
servant-foreign/test/Servant/ForeignSpec.hs+4−1
@@ -51,6 +51,9 @@ instance OVERLAPPING_ HasForeignType LangX String String where
5151instance OVERLAPPABLE_ HasForeignType LangX String a => HasForeignType LangX String [a] where
5252 typeFor lang ftype _ = "listX of " <> typeFor lang ftype (Proxy :: Proxy a)
5353
54+instance (HasForeignType LangX String a) => HasForeignType LangX String (Maybe a) where
55+ typeFor lang ftype _ = "maybe " <> typeFor lang ftype (Proxy :: Proxy a)
56+
5457type TestApi
5558 = "test" :> Header "header" [String] :> QueryFlag "flag" :> Get '[JSON] Int
5659 :<|> "test" :> QueryParam "param" Int :> ReqBody '[JSON] [String] :> Post '[JSON] NoContent
@@ -75,7 +78,7 @@ listFromAPISpec = describe "listFromAPI" $ do
7578 [ Segment $ Static "test" ]
7679 [ QueryArg (Arg "flag" "boolX") Flag ]
7780 , _reqMethod = "GET"
78− , _reqHeaders = [HeaderArg $ Arg "header" "listX of stringX"]
81+ , _reqHeaders = [HeaderArg $ Arg "header" "maybe listX of stringX"]
7982 , _reqBody = Nothing
8083 , _reqReturnType = Just "intX"
8184 , _reqFuncName = FunctionName ["get", "test"]