@@ -11,20 +11,23 @@ import Data.List.Split (splitOn)
1111import Data.Maybe (mapMaybe)
1212import Language.Haskell.TH.Quote
1313import Language.Haskell.TH
14+import Safe (headMay)
1415
1516import Servant.API.Capture
1617import Servant.API.Get
1718import Servant.API.Post
1819import Servant.API.Put
1920import Servant.API.Delete
20−import Servant.API.RQBody
21+import Servant.API.QueryParam
22+import Servant.API.ReqBody
2123import Servant.API.Sub
2224import Servant.API.Union
2325
2426class ExpSYM repr' repr | repr -> repr', repr' -> repr where
2527 lit :: String -> repr' -> repr
2628 capture :: String -> String -> repr -> repr
27− rqBody :: String -> repr -> repr
29+ reqBody :: String -> repr -> repr
30+ queryParam :: String -> String -> repr -> repr
2831 conj :: repr' -> repr -> repr
2932 get :: String -> repr
3033 post :: String -> repr
@@ -41,13 +44,15 @@ instance ExpSYM Type Type where
4144 lit name r = (LitT (StrTyLit name)) >: r
4245 capture name typ r = (AppT (AppT (ConT ''Capture) (LitT (StrTyLit name)))
4346 (ConT $ mkName typ)) >: r
44− rqBody typ r = (AppT (ConT ''RQBody) (ConT $ mkName typ)) >: r
45− conj x y = AppT (AppT (ConT ''(:>)) x) y
46− get typ = AppT (ConT ''Get) (ConT $ mkName typ)
47− post typ = AppT (ConT ''Post) (ConT $ mkName typ)
48− put typ = AppT (ConT ''Put) (ConT $ mkName typ)
49− delete "()" = ConT ''Delete
50− delete _ = error "Delete does not return a request body"
47+ reqBody typ r = (AppT (ConT ''ReqBody) (ConT $ mkName typ)) >: r
48+ queryParam name typ r = (AppT (AppT (ConT ''QueryParam) (LitT (StrTyLit name)))
49+ (ConT $ mkName typ)) >: r
50+ conj x y = AppT (AppT (ConT ''(:>)) x) y
51+ get typ = AppT (ConT ''Get) (ConT $ mkName typ)
52+ post typ = AppT (ConT ''Post) (ConT $ mkName typ)
53+ put typ = AppT (ConT ''Put) (ConT $ mkName typ)
54+ delete "()" = ConT ''Delete
55+ delete _ = error "Delete does not return a request body"
5156
5257readEntry :: ExpSYM r r => [String] -> Maybe r
5358readEntry [] = Nothing
@@ -61,7 +66,7 @@ readEntry (met:xs:typ) = case met of
6166 rd m = case typ' of
6267 [] -> readEntry' xs $ m "()"
6368 [rsp] -> readEntry' xs $ m rsp
64− (rqbd:[rsp]) -> readEntry' xs $ rqBody rqbd $ m rsp
69+ (rqbd:[rsp]) -> readEntry' xs $ reqBody rqbd $ m rsp
6570 _ -> error "Only functions of one argument allowed!"
6671readEntry x = error $ "Wrong number of elems in line: " ++ show x
6772
@@ -70,7 +75,10 @@ readEntry' [] _ = Nothing
7075readEntry' xs r = Just $ foldr1 (.) (tRepr <$> splitOn "/" xs) r
7176 where
7277 tRepr y | [x] <- splitOn ":" y = lit x
73− | a:[b] <- splitOn ":" y = capture a b
78+ | a:[b] <- splitOn ":" y = case headMay a of
79+ Just '?' -> queryParam (tail a) b
80+ Just _ -> capture a b
81+ Nothing -> error "Expecting something after '/'"
7482 | otherwise = error "Only one ':' per section"
7583
7684readAll :: String -> Type