@@ -18,6 +18,7 @@ import Data.Foldable (find, foldl', foldr')
1818import Data.Hashable
1919import qualified Data.HashMap.Strict as Map
2020import Data.Maybe
21+import Data.Maybe
2122import Data.Semigroup ((<>))
2223import Data.String
2324import Data.Text (Text)
@@ -94,8 +95,8 @@ verbAlias n m = TypeDecl noLoc n [] alias
9495 typ = tycon "'[JSON]"
9596 res = maybe (tycon "()") (tycon . Free) (_mResponse m)
9697
97−requestDecl :: Id -> Pre -> Name -> Name -> [Local] -> Maybe Id -> Decl
98−requestDecl n p api url fs rq =
98+requestDecl :: Id -> Pre -> Name -> Name -> [Local] -> Method a -> Decl
99+requestDecl n p api url fs m =
99100 -- FIXME: associated Rs type
100101 InstDecl noLoc Nothing [] [] (unqual "GoogleRequest") [tycon n]
101102 [ response
@@ -104,7 +105,7 @@ requestDecl n p api url fs rq =
104105 ]
105106 where
106107 response = InsType noLoc (TyApp (tycon "Rs") (tycon n)) $
107− maybe unit_tycon tycon rq
108+ maybe unit_tycon tycon (Free <$> _mResponse m)
108109
109110 request = funD "request" $
110111 appFun (var "requestWithRoute") [var "defReq", var url]
@@ -123,7 +124,16 @@ requestDecl n p api url fs rq =
123124 ]
124125 ]
125126
126− rhs = UnGuardedRhs . appFun (var "go") $ map (var . fname p) fs
127+ rhs = UnGuardedRhs $ appFun (var "go") (map go fs)
128+ where
129+ go l | Just p <- Map.lookup l ps
130+ , _prmLocation p == Query
131+ , parameter p || isJust (p ^. defaulted)
132+ = app (var "Just") (v l)
133+ | otherwise = v l
134+
135+ ps = _mParameters m
136+ v = var . fname p
127137
128138 pats = [pvar "r", pvar "u", prec]
129139 prec = PRec (UnQual (dname n)) [PFieldWildcard]