12
12
{-# LANGUAGE MultiParamTypeClasses #-}
13
13
{-# LANGUAGE StandaloneDeriving #-}
14
14
{-# LANGUAGE UndecidableInstances #-}
15
+ {-# LANGUAGE TypeApplications #-}
15
16
-- | @multipart/form-data@ support for servant.
16
17
--
17
18
-- This is mostly useful for adding file upload support to
@@ -35,7 +36,7 @@ module Servant.Multipart
35
36
, ToMultipartSample (.. )
36
37
) where
37
38
38
- import Control.Lens ((<>~) , (&) , view )
39
+ import Control.Lens ((<>~) , (&) , view , (.~) )
39
40
import Control.Monad.IO.Class
40
41
import Control.Monad.Trans.Resource
41
42
import Data.Foldable (foldMap )
@@ -49,6 +50,7 @@ import Network.Wai
49
50
import Network.Wai.Parse
50
51
import Servant
51
52
import Servant.Docs
53
+ import Servant.Foreign
52
54
import Servant.Server.Internal
53
55
import System.Directory
54
56
@@ -525,3 +527,14 @@ instance (HasDocs api, ToMultipartSample tag a) => HasDocs (MultipartForm tag a
525
527
(Proxy :: Proxy a )
526
528
]
527
529
in docsFor (Proxy :: Proxy api ) (endpoint, newAction) opts
530
+
531
+ instance (HasForeignType lang ftype a , HasForeign lang ftype api )
532
+ => HasForeign lang ftype (MultipartForm t a :> api ) where
533
+ type Foreign ftype (MultipartForm t a :> api ) = Foreign ftype api
534
+
535
+ foreignFor lang ftype Proxy req =
536
+ foreignFor lang ftype (Proxy @ api ) $
537
+ req & reqBody .~ Just t
538
+ & reqBodyIsJSON .~ False
539
+ where
540
+ t = typeFor lang ftype (Proxy @ a )
0 commit comments