on develop help sign in
Rendering multipart servant link
6406925Brendan Hay
gen/src/Gen/Syntax.hs+14−3
@@ -49,9 +49,9 @@ apiAlias n ls = TypeDecl noLoc n [] alias
49
49
50-- type Method = :> ...
50-- type Method = :> ...
51verbAlias :: Name -> Method Solved -> Decl
51verbAlias :: Name -> Method Solved -> Decl
52−verbAlias n m = TypeDecl noLoc n [] alias
52+verbAlias n m = TypeDecl noLoc n [] (alias (path ++ qry ++ media))
53 where
53 where
54− alias = foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r) verb (path ++ qry)
54+ alias = foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r) verb
55
55
56 -- FIXME: rather than using 'terminal' to get the terminal type,
56 -- FIXME: rather than using 'terminal' to get the terminal type,
57 -- write a custom 'Link' for servant to specify required params.
57 -- write a custom 'Link' for servant to specify required params.
@@ -85,7 +85,16 @@ verbAlias n m = TypeDecl noLoc n [] alias
85 Query -> Just $ TyApp (TyApp (TyCon "QueryParam") n) t
85 Query -> Just $ TyApp (TyApp (TyCon "QueryParam") n) t
86 Path -> Nothing
86 Path -> Nothing
87
87
88− params = _mParameters m
88+ media :: [Type]
89+ media | Just b <- _mRequest m =
90+ let g = ref b
91+ in if _mSupportsMediaUpload m
92+ then [TyApp (TyApp (TyCon "Multipart") typ) (parts g)]
93+ else [TyApp (TyApp (TyCon "ReqBody") typ) (tycon g)]
94+ | otherwise = []
95+ where
96+ parts g = TyCon (UnQual (name (Text.unpack ("'[" <> global g <> ", Body]"))))
97+ typ = TyCon "'[JSON]"
89
98
90 verb :: Type
99 verb :: Type
91 verb = TyApp (TyApp meth typ) res
100 verb = TyApp (TyApp meth typ) res
@@ -94,6 +103,8 @@ verbAlias n m = TypeDecl noLoc n [] alias
94 typ = TyCon "'[JSON]"
103 typ = TyCon "'[JSON]"
95 res = maybe (TyCon "()") (tycon . ref) (_mResponse m)
104 res = maybe (TyCon "()") (tycon . ref) (_mResponse m)
96
105
106+ params = _mParameters m
107+
97requestDecl :: Global
108requestDecl :: Global
98 -> Prefix
109 -> Prefix
99 -> Name
110 -> Name
gen/src/Gen/Text.hs+1−1
@@ -197,7 +197,7 @@ upperAcronym x = Fold.foldl' (flip (uncurry RE.replaceAll)) x xs
197 , ("Youtube", "YouTube")
197 , ("Youtube", "YouTube")
198 , ("Cnc", "CNC")
198 , ("Cnc", "CNC")
199 , ("Oauth", "OAuth")
199 , ("Oauth", "OAuth")
200− , ("Ocr$", "OCR")
200+ , ("Ocr", "OCR")
201 ]
201 ]
202
202
203acronyms :: [(String, String)]
203acronyms :: [(String, String)]