on develop help sign in
Adding resource method documentation
db23894Brendan Hay
gen/src/Gen/AST.hs+6−3
@@ -106,18 +106,21 @@ render svc = do
106 sub l = \case
106 sub l = \case
107 t@(Top rs) -> do
107 t@(Top rs) -> do
108 let k = nname l
108 let k = nname l
109+ t <- Action k Nothing
109− t <- Action k <$> pp Print (apiAlias k (nouns t))
110+ <$> pp Print (apiAlias k (nouns t))
110 as <- traverse (uncurry sub) (Map.toList rs) <&> concat
111 as <- traverse (uncurry sub) (Map.toList rs) <&> concat
111 return (t : as)
112 return (t : as)
112
113
113 Sub ms -> do
114 Sub ms -> do
114 let k = nname l
115 let k = nname l
116+ t <- Action k Nothing
115− t <- Action k <$> pp Print (apiAlias k (map (vname l) $ Map.keys ms))
117+ <$> pp Print (apiAlias k (map (vname l) $ Map.keys ms))
116 as <- traverse (uncurry (verb l)) (Map.toList ms)
118 as <- traverse (uncurry (verb l)) (Map.toList ms)
117 return (t : as)
119 return (t : as)
118
120
119 verb :: Local -> Local -> Method -> AST Action
121 verb :: Local -> Local -> Method -> AST Action
122+ verb p l m = Action (vname p l) (_mDescription m)
120− verb p l m = Action (vname p l) <$> pp Print (verbDecl svc p l m)
123+ <$> pp Print (verbDecl svc p l m)
121
124
122flatten :: Service (Fix Schema) Resource -> Service (Schema Id) Resource
125flatten :: Service (Fix Schema) Resource -> Service (Schema Id) Resource
123flatten svc = svc { _svcSchemas = execState run mempty }
126flatten svc = svc { _svcSchemas = execState run mempty }
gen/src/Gen/Types.hs+3−2
@@ -326,11 +326,12 @@ instance ToJSON Data where
326 , "lenses" .= ls
326 , "lenses" .= ls
327 ]
327 ]
328
328
329−data Action = Action Name Rendered
329+data Action = Action Name (Maybe Help) Rendered
330
330
331instance ToJSON Action where
331instance ToJSON Action where
332− toJSON (Action n d) = object
332+ toJSON (Action n h d) = object
333 [ "name" .= Syn n
333 [ "name" .= Syn n
334+ , "help" .= h
334 , "decl" .= d
335 , "decl" .= d
335 ]
336 ]
336
337
gen/src/Gen/Types/Id.hs+2−4
@@ -2,6 +2,7 @@
2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE LambdaCase #-}
4{-# LANGUAGE LambdaCase #-}
5+{-# LANGUAGE OverloadedStrings #-}
5
6
6-- Module : Gen.Types.Id
7-- Module : Gen.Types.Id
7-- Copyright : (c) 2015 Brendan Hay
8-- Copyright : (c) 2015 Brendan Hay
@@ -41,11 +42,8 @@ import Language.Haskell.Exts.Build
41import Language.Haskell.Exts.Pretty (prettyPrint)
42import Language.Haskell.Exts.Pretty (prettyPrint)
42import Language.Haskell.Exts.Syntax (Name)
43import Language.Haskell.Exts.Syntax (Name)
43
44
44−aname :: Id -> Name
45−aname = name . Text.unpack . upperHead . idToText
46−
47nname :: Local -> Name
45nname :: Local -> Name
48−nname = name . Text.unpack . upperHead . local
46+nname = name . Text.unpack . (<> "API") . upperHead . local
49
47
50vname :: Local -> Local -> Name
48vname :: Local -> Local -> Name
51vname p l = name (f p <> f l)
49vname p l = name (f p <> f l)
gen/template/toc.ede+6−8
@@ -7,14 +7,9 @@ module {{ moduleName }}
7 (
7 (
8 -- * Resources
8 -- * Resources
9 {{ api.name }}
9 {{ api.name }}
10− {# {% for act in api.actions %} #}
10+ {% for action in api.actions %}
11−
11+ , {{ action.value.name }}
12− {# -- ** {{ act.value.name }} #}
13− {# , {{ act.value.name }} #}
14− {# {% for nv in act.value.actions %} #}
15− {# , {{ nv.value.name }} #}
16− {# {% endfor %} #}
12+ {% endfor %}
17− {# {% endfor %} #}
18
13
19 -- * Types
14 -- * Types
20 {% for schema in schemas %}
15 {% for schema in schemas %}
@@ -48,5 +43,8 @@ TODO
48{{ api.decl }}
43{{ api.decl }}
49{% for action in api.actions %}
44{% for action in api.actions %}
50
45
46+{% if action.value.help %}
47+{{ action.value.help }}
48+{% endif %}
51{{ action.value.decl }}
49{{ action.value.decl }}
52{% endfor %}
50{% endfor %}