git.iko.soy/typeable/servant
on master help sign in
Temporary fix for Header. (#843)
c1371ddDimitri Sabadie
servant-foreign/src/Servant/Foreign/Internal.hs+2−2
@@ -225,7 +225,7 @@ instance (Elem JSON list, HasForeignType lang ftype a, ReflectMethod method)
225 method = reflectMethod (Proxy :: Proxy method)
225 method = reflectMethod (Proxy :: Proxy method)
226 methodLC = toLower $ decodeUtf8 method
226 methodLC = toLower $ decodeUtf8 method
227
227
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)
229 => HasForeign lang ftype (Header sym a :> api) where
229 => HasForeign lang ftype (Header sym a :> api) where
230 type Foreign ftype (Header sym a :> api) = Foreign ftype api
230 type Foreign ftype (Header sym a :> api) = Foreign ftype api
231
231
@@ -235,7 +235,7 @@ instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype ap
235 hname = pack . symbolVal $ (Proxy :: Proxy sym)
235 hname = pack . symbolVal $ (Proxy :: Proxy sym)
236 arg = Arg
236 arg = Arg
237 { _argName = PathSegment hname
237 { _argName = PathSegment hname
238− , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy a) }
238+ , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy (Maybe a)) }
239 subP = Proxy :: Proxy api
239 subP = Proxy :: Proxy api
240
240
241instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype api)
241instance (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
51instance OVERLAPPABLE_ HasForeignType LangX String a => HasForeignType LangX String [a] where
51instance OVERLAPPABLE_ HasForeignType LangX String a => HasForeignType LangX String [a] where
52 typeFor lang ftype _ = "listX of " <> typeFor lang ftype (Proxy :: Proxy a)
52 typeFor lang ftype _ = "listX of " <> typeFor lang ftype (Proxy :: Proxy a)
53
53
54+instance (HasForeignType LangX String a) => HasForeignType LangX String (Maybe a) where
55+ typeFor lang ftype _ = "maybe " <> typeFor lang ftype (Proxy :: Proxy a)
56+
54type TestApi
57type TestApi
55 = "test" :> Header "header" [String] :> QueryFlag "flag" :> Get '[JSON] Int
58 = "test" :> Header "header" [String] :> QueryFlag "flag" :> Get '[JSON] Int
56 :<|> "test" :> QueryParam "param" Int :> ReqBody '[JSON] [String] :> Post '[JSON] NoContent
59 :<|> "test" :> QueryParam "param" Int :> ReqBody '[JSON] [String] :> Post '[JSON] NoContent
@@ -75,7 +78,7 @@ listFromAPISpec = describe "listFromAPI" $ do
75 [ Segment $ Static "test" ]
78 [ Segment $ Static "test" ]
76 [ QueryArg (Arg "flag" "boolX") Flag ]
79 [ QueryArg (Arg "flag" "boolX") Flag ]
77 , _reqMethod = "GET"
80 , _reqMethod = "GET"
78− , _reqHeaders = [HeaderArg $ Arg "header" "listX of stringX"]
81+ , _reqHeaders = [HeaderArg $ Arg "header" "maybe listX of stringX"]
79 , _reqBody = Nothing
82 , _reqBody = Nothing
80 , _reqReturnType = Just "intX"
83 , _reqReturnType = Just "intX"
81 , _reqFuncName = FunctionName ["get", "test"]
84 , _reqFuncName = FunctionName ["get", "test"]