on develop help sign in
Re-enabling path/query generation
3ad8335Brendan Hay
gen/src/Gen/AST.hs+3−2
@@ -185,8 +185,9 @@ flatten svc = do
185 ms <- uses schemas (Map.lookup n)
185 ms <- uses schemas (Map.lookup n)
186 case ms of
186 case ms of
187 Just y | x /= y -> throwError $
187 Just y | x /= y -> throwError $
188− format ("Schema exists: " % shown % "\nTried inserting: " % shown)
188+ format ("Schema exists: " % fid %
189+ "\nCurrent: " % shown % "\nTried: " % shown)
189− y x
190+ n y x
190 _ -> schemas %= Map.insert n x
191 _ -> schemas %= Map.insert n x
191
192
192 return n
193 return n
gen/src/Gen/Syntax.hs+27−26
@@ -14,7 +14,7 @@ module Gen.Syntax where
14
14
15import Control.Lens hiding (iso, mapping, op, pre,
15import Control.Lens hiding (iso, mapping, op, pre,
16 strict)
16 strict)
17−import Data.Foldable (foldl', foldr')
17+import Data.Foldable (find, foldl', foldr')
18import Data.Hashable
18import Data.Hashable
19import qualified Data.HashMap.Strict as Map
19import qualified Data.HashMap.Strict as Map
20import Data.Maybe
20import Data.Maybe
@@ -46,34 +46,35 @@ verbAlias s n m = TypeDecl noLoc n [] alias
46 alias = foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r) verb (path ++ qry)
46 alias = foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r) verb (path ++ qry)
47
47
48 path :: [Type]
48 path :: [Type]
49− path = [] -- map match
49+ path = map match
50− -- . filter (not . Text.null)
50+ . filter (not . Text.null)
51− -- $ Text.split (== '/') (_svcServicePath s)
51+ $ Text.split (== '/') (_svcServicePath s)
52− -- <> Text.split (== '/') (_mPath m)
52+ <> Text.split (== '/') (_mPath m)
53− -- where
53+ where
54+ -- FIXME: should error if '{' '}' is found and cannot find the ref.
54− -- match x
55+ match x
55− -- | Just (c, t) <- Text.uncons x
56+ | Just (c, t) <- Text.uncons x
56− -- , c == '{'
57+ , c == '{'
57− -- , Just k <- Map.lookup (Local (Text.init t)) params
58+ , Just k <- Map.lookup (Local (Text.init t)) params
58− -- , _prmLocation k == Path
59+ , _prmLocation k == Path
59− -- = TyApp (TyApp (tycon "Capture")
60+ = TyApp (TyApp (tycon "Capture")
60− -- (sing (Text.init t)))
61+ (sing (Text.init t)))
61− -- (literal (_prmLiteral k))
62+ (external (_type (_prmSchema k)))
62− -- | otherwise = sing x
63+ | otherwise = sing x
63
64
64 -- FIXME: order by _mParameterOrder
65 -- FIXME: order by _mParameterOrder
65 qry :: [Type]
66 qry :: [Type]
66− qry = [] -- mapMaybe f (Map.toList params)
67+ qry = mapMaybe f (Map.toList params)
67− -- where
68+ where
68− -- f (k, p) =
69+ f (k, x) =
69− -- -- FIXME: types, many/repeated
70+ -- FIXME: types, many/repeated
70− -- let t = literal (_prmLiteral p)
71+ let t = external (_type (_prmSchema x))
71− -- n = sing (local k)
72+ n = sing (local k)
72− -- in case _prmLocation p of
73+ in case _prmLocation x of
73− -- Query -> Just $ TyApp (TyApp (tycon "QueryParam") n) t
74+ Query -> Just $ TyApp (TyApp (tycon "QueryParam") n) t
74− -- Path -> Nothing
75+ Path -> Nothing
75−
76+
76−-- params = _svcParameters s <> _mParameters m
77+ params = _mParameters m
77
78
78 verb :: Type
79 verb :: Type
79 verb = TyApp (TyApp meth typ) res
80 verb = TyApp (TyApp meth typ) res