on develop help sign in
Modifying template variables to reflect updated JSON environment
commit3c58ff8419ec8c58c0f069f66654749c3bc53b62 authorBrendan Hay <brendan.g.hay@gmail.com> dateWed 30 Sep 2015, 11:32 (11 years ago) parentd767f90
13 files changed+152−254
gen/src/Gen/AST/Flatten.hs+31−11 gen/src/Gen/AST/Render.hs−37 gen/src/Gen/AST/Solve.hs+6−4 gen/src/Gen/Syntax.hs+2−2 gen/src/Gen/Types.hs+28−10 gen/src/Gen/Types/Data.hs+1−1 gen/src/Gen/Types/Id.hs+29−30 gen/src/Gen/Types/Map.hs+2−3 gen/src/Gen/Types/NS.hs+2−1 gen/src/Gen/Types/Schema.hs+41−143 gen/template/action.ede+3−3 gen/template/cabal.ede+1−3 gen/template/toc.ede+6−6
gen/src/Gen/AST/Flatten.hs+31−11
@@ -44,10 +44,10 @@ import Prelude hiding (sum)
4444
4545flatten :: Service (Fix Schema) -> AST (Service Global)
4646flatten s = do
47− ss <- Map.traverseWithKey globalSchema (s ^. dSchemas)
48− ps <- Map.traverseWithKey globalParam (s ^. dParameters)
49− rs <- Map.traverseWithKey resource (s ^. dResources)
50− ms <- traverse method (s ^. dMethods)
47+ ss <- Map.traverseWithKey globalSchema (s ^. dSchemas)
48+ ps <- Map.traverseWithKey globalParam (s ^. dParameters)
49+ rs <- Map.traverseWithKey (resource ps) (s ^. dResources)
50+ ms <- traverse (method ps) (s ^. dMethods)
5151
5252 let d = (s ^. sDescription)
5353 { _dSchemas = ss
@@ -93,21 +93,41 @@ localParam g l p = do
9393 x <- localSchema g l (_pParam p)
9494 pure $! p { _pParam = x }
9595
96−resource :: Global
96+resource :: Map Local (Param Global)
97+ -> Global
9798 -> Resource (Fix Schema)
9899 -> AST (Resource Global)
99−resource g r = do
100− rs <- Map.traverseWithKey (\l -> resource (reference g l)) (_rResources r)
101− ms <- traverse method (_rMethods r)
100+resource qs g r@Resource {..} = do
101+ rs <- Map.traverseWithKey (\l -> resource qs (reference g l)) _rResources
102+ ms <- traverse (method qs) _rMethods
102103 pure $! r
103104 { _rResources = rs
104105 , _rMethods = ms
105106 }
106107
107−method :: Method (Fix Schema) -> AST (Method Global)
108−method m = do
109− ps <- Map.traverseWithKey (localParam (_mId m)) (_mParameters m)
108+method :: Map Local (Param Global)
109+ -> Method (Fix Schema)
110+ -> AST (Method Global)
111+method qs m@Method {..} = do
112+ ps <- Map.traverseWithKey (localParam _mId) _mParameters
113+ cn <- use sCanonicalName
114+ let (_, typ, _) = mname cn _mId
115+ void $ insert typ (fresh ps)
110116 pure $! m { _mParameters = ps }
117+ where
118+ fresh ps = SObj info' $ Obj Nothing (Map.map _pParam (ps <> qs))
119+
120+ info' = Info
121+ { _iId = Nothing
122+ , _iDescription = _mDescription
123+ , _iDefault = Nothing
124+ , _iRequired = False
125+ , _iPattern = Nothing
126+ , _iMinimum = Nothing
127+ , _iMaximum = Nothing
128+ , _iRepeated = False
129+ , _iAnnotations = mempty
130+ }
111131
112132setRequired :: Fix Schema -> Fix Schema
113133setRequired (Fix e) = Fix (e & iRequired .~ True)
gen/src/Gen/AST/Render.hs−37
@@ -156,43 +156,6 @@ renderAPI s = do
156156 "@ of the " % stext % ".")
157157 (s ^. dVersion) (s ^. dTitle)
158158
159−-- api :: Resource Solved -> AST API
160−-- api x = do
161−-- as <- Map.fromList <$> top x
162−-- API n <$> pp Print (apiAlias n (Map.keys as))
163−-- <*> pure as
164−-- <*> url
165−-- where
166−-- n = name (Text.unpack (svcAbbrev svc))
167−-- un = name (Text.unpack (svcURL svc))
168−
169−-- top = \case
170−-- Top rs -> traverse (uncurry sub) (Map.toList rs) <&> concat
171−-- Sub ms -> traverse (uncurry verb) (Map.toList ms)
172−
173−-- sub l = \case
174−-- Top rs -> traverse (uncurry sub) (Map.toList rs) <&> concat
175−-- Sub ms -> traverse (uncurry verb) (Map.toList ms)
176−
177−-- verb l m = do
178−-- let (k, i, ns) = vname (svcAbbrev svc) (_mId m)
179−-- s <- solve i
180−-- Just d <- typ s
181−-- fmap (k,) $
182−-- Action k (_mId m) (actionNS ns) (_mDescription m)
183−-- <$> pp Print (verbAlias k m)
184−-- <*> reset k m s d
185−
186−-- reset k m s = \case
187−-- d@Sum {} -> pure d
188−-- Prod n' h r c ls _ ->
189−-- Prod n' h r c ls . (:[]) <$> pp Print
190−-- (requestDecl (_ident s) (_prefix s) k un (fields (_schema s)) m)
191−
192−-- fields = \case
193−-- Obj _ rs -> Map.keys rs
194−-- _ -> mempty
195−
196159data PP
197160 = Indent
198161 | Print
gen/src/Gen/AST/Solve.hs+6−4
@@ -78,10 +78,12 @@ getSolved g = loc "getSolved" g $
7878
7979getSchema :: Global -> AST (Schema Global)
8080getSchema g = do
81− m <- uses schemas (Map.lookup g)
82− case m of
83− Nothing -> failure ("Missing Schema: " % gid) g
81+ ss <- use schemas
82+ case Map.lookup g ss of
8483 Just x -> pure x
84+ Nothing -> throwError $
85+ format ("Missing Schema: " % gid % "\n" % shown)
86+ g (map global (Map.keys ss))
8587
8688getType :: Global -> AST TType
8789getType g = loc "getType" g $ memo typed g go
@@ -214,7 +216,7 @@ acronymPrefixes (global -> g) = map CI.mk (xs ++ map suffix ys ++ zs)
214216 r6 = Text.take limit <$> listToMaybe (splitWords a)
215217
216218loc :: String -> Global -> a -> a
217−loc _ _ = id --trace (n ++ ": " ++ Text.unpack (idToText g))
219+loc n g = id -- trace (n ++ ": " ++ Text.unpack (fromKey g))
218220
219221memo :: Lens' Memo (Map Global a)
220222 -> Global
gen/src/Gen/Syntax.hs+2−2
@@ -146,7 +146,7 @@ jsonDecls n p (Map.toList -> rs) = [from, to]
146146 where
147147 from = InstDecl noLoc Nothing [] [] (unqual "FromJSON") [tycon n]
148148 [ funD "parseJSON" $
149− app (app (var "withObject") (str (fromKey n))) $
149+ app (app (var "withObject") (str (global n))) $
150150 lamE noLoc [pvar "o"] $
151151 ctorE n (map decode rs)
152152 ]
@@ -372,7 +372,7 @@ sing :: Text -> Type
372372sing = TyCon . unqual . Text.unpack . flip mappend "\"" . mappend "\""
373373
374374tycon :: Global -> Type
375−tycon = TyCon . unqual . Text.unpack . fromKey
375+tycon = TyCon . unqual . Text.unpack . global
376376
377377unqual :: String -> QName
378378unqual = UnQual . name
gen/src/Gen/Types.hs+28−10
@@ -165,14 +165,15 @@ sumNS = (<> "Sum") . typesNS
165165preludeNS :: NS
166166preludeNS = "Network.Google.Prelude"
167167
168−-- actionNS :: [Text] -> NS
169−-- actionNS = mappend (NS ["Network", "Google", "API"]) . NS
168+exposedModules :: Library -> [NS]
169+exposedModules l = sort $
170+ tocNS l
171+ : typesNS l
172+ : map resourceNS (_apiResources (_lAPI l))
173+ ++ map methodNS (_apiMethods (_lAPI l))
170174
171−-- exposedModules :: Service s p API -> [NS]
172−-- exposedModules s = sort (tocNS s : typesNS s : map _actNS (svcActions s))
173−
174−-- otherModules :: Service s p r -> [NS]
175−-- otherModules s = sort [prodNS s, sumNS s]
175+otherModules :: Library -> [NS]
176+otherModules s = sort [prodNS s, sumNS s]
176177
177178toTextIgnore :: Path -> Text
178179toTextIgnore = either id id . Path.toText
@@ -197,15 +198,32 @@ instance HasService Library Global where
197198
198199instance ToJSON Library where
199200 toJSON l = object
201+ -- Library
200202 [ "libraryName" .= (l ^. sLibrary)
201203 , "libraryTitle" .= (l ^. dTitle)
202204 , "libraryDescription" .= Desc 4 (l ^. dDescription)
203205 , "libraryVersion" .= (l ^. libraryVersion)
204206 , "coreVersion" .= (l ^. coreVersion)
205207 , "clientVersion" .= (l ^. clientVersion)
206− -- , "exposedModules" .= concatMap exposedModules (NE.toList _libServices)
207− -- , "otherModules" .= concatMap otherModules (NE.toList _libServices)
208− ]
208+ , "exposedModules" .= exposedModules l
209+ , "otherModules" .= otherModules l
210+
211+ -- Service
212+ , "id" .= (l ^. dId)
213+ , "name" .= (l ^. dName)
214+ , "version" .= (l ^. dVersion)
215+ , "title" .= (l ^. dTitle)
216+ , "description" .= (l ^. dDescription)
217+ , "documentationLink" .= (l ^. dDocumentationLink)
218+ , "labels" .= (l ^. dLabels)
219+ , "features" .= (l ^. dFeatures)
220+
221+ -- API
222+ , "api" .= (l ^. lAPI)
223+
224+ -- Schemas
225+ , "schemas" .= (l ^. lSchemas)
226+ ]
209227
210228data TType
211229 = TType Global
gen/src/Gen/Types/Data.hs+1−1
@@ -150,6 +150,7 @@ data API = API
150150instance ToJSON API where
151151 toJSON API {..} = object
152152 [ "aliasName" .= Syn _apiAliasName
153+ , "aliasProxy".= lowerHead (Text.pack (prettyPrint _apiAliasName))
153154 , "alias" .= _apiAlias
154155 , "resources" .= sortOn _actId _apiResources
155156 , "methods" .= sortOn _actId _apiMethods
@@ -163,4 +164,3 @@ instance ToJSON API where
163164resourceNS, methodNS :: Action -> NS
164165resourceNS = mappend "Network.Google.Resource" . _actNamespace
165166methodNS = mappend "Network.Google.Method" . _actNamespace
166−
gen/src/Gen/Types/Id.hs+29−30
@@ -47,6 +47,7 @@ import qualified Data.Attoparsec.Text as A
4747import Data.Bifunctor
4848import qualified Data.CaseInsensitive as CI
4949import Data.Char
50+import Data.Foldable (foldMap)
5051import Data.Function (on)
5152import Data.Hashable
5253import qualified Data.HashMap.Strict as Map
@@ -74,35 +75,23 @@ aname :: Text -> Name
7475aname = name . Text.unpack . mappend "API" . upperHead . Text.replace "." ""
7576
7677mname :: Text -> Global -> (Name, Global, Text)
77−mname abrv g =
78− ( name (Text.unpack n <> "API") -- Action service type alias.
79− , Global (n <> "'") -- Action data type.
80− , Text.intercalate "." ns -- Action namespace.
78+mname abrv (Global g) =
79+ ( name (Text.unpack (mconcat n) <> "API") -- Action service type alias.
80+ , Global (n <> ["'"]) -- Action data type.
81+ , Text.intercalate "." ns -- Action namespace.
8182 )
8283 where
83− n = mconcat (drop 1 ns)
84+ n = drop 1 ns
8485
8586 ns | CI.mk e == CI.mk x = e:xs
8687 | otherwise = x:xs
8788 where
8889 e = Text.replace "." "" abrv
89− x:xs = map (upperAcronym . upperHead) $ Text.split (== '.') (global g)
90−
91−-- vname :: Text -> Text -> (Name, Id, [Text])
92−-- vname abrv r = (dname (g (n <> "API")), g (n <> "'"), ns)
93−-- where
94−-- g = Free . Global
95−-- n = mconcat (drop 1 ns)
96−
97−-- ns | CI.mk e == CI.mk x = e:xs
98−-- | otherwise = x:xs
99−-- where
100−-- e = Text.replace "." "" abrv
101−-- x:xs = map (upperAcronym . upperHead) $ Text.split (== '.') r
90+ x:xs = g
10291
10392dname, cname :: Global -> Name
104−dname = name . Text.unpack . upperHead . global
105−cname = name . Text.unpack . renameReserved . lowerHead . global
93+dname = name . Text.unpack . toPascal . global
94+cname = name . Text.unpack . renameReserved . toCamel . global
10695
10796bname :: Prefix -> Text -> Name
10897bname (Prefix p) = name
@@ -115,21 +104,26 @@ fname = pre (Text.cons '_' . renameField)
115104lname = pre renameField
116105pname = pre (flip Text.snoc '_' . Text.cons 'p' . upperHead . renameField)
117106
118−-- apretty :: Local -> Local -> Text
119−-- apretty p l = upperHead (local l) <> " " <> upperHead (local p)
120−
121107pre :: (Text -> Text) -> Prefix -> Local -> Name
122108pre f (Prefix p) = name . Text.unpack . f . mappend p . upperHead . local
123109
124110newtype Prefix = Prefix Text
125111 deriving (Show, Monoid)
126112
127−newtype Global = Global { global :: Text }
128− deriving (Eq, Ord, Show, Generic, Hashable, FromJSON, ToJSON, IsString)
113+newtype Global = Global [Text]
114+ deriving (Eq, Ord, Show, Generic, Hashable)
115+
116+instance IsString Global where
117+ fromString = mkGlobal . fromString
118+
119+instance FromJSON Global where
120+ parseJSON = withText "global" (pure . mkGlobal)
121+
122+instance ToJSON Global where
123+ toJSON = toJSON . global
129124
130125instance TextKey Global where
131− toKey = Global
132− fromKey = global
126+ toKey = mkGlobal
133127
134128gid :: Format a (Global -> a)
135129gid = later (Build.fromText . global)
@@ -138,11 +132,16 @@ newtype Local = Local { local :: Text }
138132 deriving (Eq, Ord, Show, Generic, Hashable, FromJSON, ToJSON, IsString)
139133
140134instance TextKey Local where
141− toKey = Local
142− fromKey = local
135+ toKey = Local
143136
144137lid :: Format a (Local -> a)
145138lid = later (Build.fromText . local)
146139
140+mkGlobal :: Text -> Global
141+mkGlobal = Global . Text.split (== '.')
142+
143+global :: Global -> Text
144+global (Global g) = foldMap (upperAcronym . upperHead) g
145+
147146reference :: Global -> Local -> Global
148−reference (Global g) (Local l) = Global (g <> "." <> l)
147+reference (Global g) (Local l) = Global (g <> Text.split (== '.') l)
gen/src/Gen/Types/Map.hs+2−3
@@ -40,11 +40,10 @@ kvTraverseMaybe f = fmap (Map.map fromJust . Map.filter isJust)
4040
4141class (Hashable a, Eq a) => TextKey a where
4242 toKey :: Text -> a
43− fromKey :: a -> Text
4443
4544instance (TextKey k, FromJSON v) => FromJSON (Map k v) where
4645 parseJSON = fmap (Map.fromList . map (first toKey) . Map.toList)
4746 . parseJSON
4847
49−instance (TextKey k, ToJSON v) => ToJSON (Map k v) where
50− toJSON = toJSON . map (first fromKey) . Map.toList
48+-- instance (TextKey k, ToJSON v) => ToJSON (Map k v) where
49+-- toJSON = toJSON . map (first fromKey) . Map.toList
gen/src/Gen/Types/NS.hs+2−1
@@ -21,6 +21,7 @@ import Data.Semigroup
2121import Data.String
2222import Data.Text (Text)
2323import qualified Data.Text as Text
24+import Data.Text.Manipulate
2425import qualified Filesystem.Path.CurrentOS as Path
2526import Gen.Text
2627
@@ -28,7 +29,7 @@ newtype NS = NS { unNS :: [Text] }
2829 deriving (Eq, Ord, Show)
2930
3031mkNS :: Text -> NS
31−mkNS = NS . Text.splitOn "."
32+mkNS = NS . map (upperAcronym . upperHead) . Text.split (== '.')
3233
3334nsToPath :: NS -> Path.FilePath
3435nsToPath (NS xs) = Path.fromText (Text.intercalate "/" xs) Path.<.> "hs"
gen/src/Gen/Types/Schema.hs+41−143
@@ -98,7 +98,7 @@ makeClassy ''Info
9898
9999instance FromJSON Info where
100100 parseJSON = withObject "info" $ \o -> Info
101− <$> o .: "id"
101+ <$> o .:? "id"
102102 <*> o .:? "description"
103103 <*> o .:? "default"
104104 <*> o .:? "required" .!= False
@@ -137,6 +137,7 @@ instance HasInfo (Schema a) where
137137 info = lens f (flip g)
138138 where
139139 f = \case
140+ SAny i _ -> i
140141 SRef i _ -> i
141142 SLit i _ -> i
142143 SEnm i _ -> i
@@ -144,6 +145,7 @@ instance HasInfo (Schema a) where
144145 SObj i _ -> i
145146
146147 g i = \case
148+ SAny _ x -> SAny i x
147149 SRef _ x -> SRef i x
148150 SLit _ x -> SLit i x
149151 SEnm _ x -> SEnm i x
@@ -155,6 +157,7 @@ checkType x o = do
155157 y <- o .: "type"
156158 unless (x == y) . fail . Text.unpack $
157159 "Schema type mismatch, expected " <> x <> ", but got " <> y
160+ <> "\n" <> Text.pack (show o)
158161
159162data Any = Any
160163 deriving (Eq, Show)
@@ -221,7 +224,7 @@ newtype Arr a = Arr { _aItem :: a }
221224instance FromJSON a => FromJSON (Arr a) where
222225 parseJSON = withObject "array" $ \o -> do
223226 checkType "array" o
224− Arr <$> o .: "item"
227+ Arr <$> o .: "items"
225228
226229data Obj a = Obj
227230 { _oAdditional :: Maybe a
@@ -284,7 +287,7 @@ instance FromJSON a => FromJSON (Method a) where
284287 <$> o .: "id"
285288 <*> o .: "path"
286289 <*> o .: "httpMethod"
287− <*> o .: "description"
290+ <*> o .:? "description"
288291 <*> o .:? "parameters" .!= mempty
289292 <*> o .:? "parameterOrder" .!= mempty
290293 <*> o .:? "request"
@@ -305,13 +308,35 @@ instance FromJSON a => FromJSON (Resource a) where
305308 <$> o .:? "resources" .!= mempty
306309 <*> (o .:? "methods" .!= mempty <&> keyless)
307310
308−newtype OAuth2 = OAuth2 { scopes :: Map Text Text }
311+newtype OAuth2 = OAuth2 { scopes :: Map Text Help }
309312 deriving (Eq, Show)
310313
311314instance FromJSON OAuth2 where
312− parseJSON = withObject "oauth2" $ \o ->
313− o .: "oauth2" >>=
314− withObject "scopes" (.: "scopes")
315+ parseJSON = withObject "oauth2" $ \x -> do
316+ y <- x .: "oauth2"
317+ z <- y .: "scopes"
318+ OAuth2 <$> traverse (.: "description") z
319+
320+data Label
321+ = Deprecated
322+ | LimitedAvailability
323+ | Labs
324+ deriving (Eq, Show)
325+
326+instance FromJSON Label where
327+ parseJSON = withText "label" $ \t ->
328+ case t of
329+ "deprecated" -> pure Deprecated
330+ "limited_availability" -> pure LimitedAvailability
331+ "labs" -> pure Labs
332+ _ -> fail $
333+ Text.unpack ("Unable to parse Label from: " <> t)
334+
335+instance ToJSON Label where
336+ toJSON = toJSON . \case
337+ Deprecated -> "deprecated" :: Text
338+ LimitedAvailability -> "limited_availability"
339+ Labs -> "labs"
315340
316341data Description a = Description
317342 { _dKind :: Text
@@ -324,14 +349,14 @@ data Description a = Description
324349 , _dDescription :: Help
325350 , _dIcons :: Map Text Text
326351 , _dDocumentationLink :: Text
327− , _dLabels :: Text
352+ , _dLabels :: [Label]
328353 , _dProtocol :: Text
329354 , _dBaseUrl :: Text
330355 , _dRootUrl :: Text
331356 , _dServicePath :: Text
332357 , _dBatchPath :: Text
333358 , _dParameters :: Map Local (Param a)
334− , _dAuth :: OAuth2
359+ , _dAuth :: Maybe OAuth2
335360 , _dFeatures :: [Text]
336361 , _dSchemas :: Map Global a
337362 , _dResources :: Map Global (Resource a)
@@ -352,14 +377,14 @@ instance FromJSON a => FromJSON (Description a) where
352377 <*> o .: "description"
353378 <*> o .: "icons"
354379 <*> o .: "documentationLink"
355− <*> o .: "labels"
380+ <*> o .:? "labels" .!= mempty
356381 <*> o .: "protocol"
357382 <*> o .: "baseUrl"
358383 <*> o .: "rootUrl"
359384 <*> o .: "servicePath"
360385 <*> o .: "batchPath"
361386 <*> o .:? "parameters" .!= mempty
362− <*> o .: "auth"
387+ <*> o .:? "auth"
363388 <*> o .:? "features" .!= mempty
364389 <*> o .:? "schemas" .!= mempty
365390 <*> o .:? "resources" .!= mempty
@@ -378,11 +403,11 @@ makeClassy ''Service
378403
379404instance FromJSON a => FromJSON (Service a) where
380405 parseJSON = withObject "service" $ \o -> Service
381− <$> o .: "library"
382− <*> (o .: "canonicalName" <&> upperHead . renameAbbrev)
383− <*> o .: "ownerName"
384− <*> o .: "ownerDomain"
385− <*> o .: "packagePath"
406+ <$> o .: "library"
407+ <*> (o .: "canonicalName" <&> upperHead . renameAbbrev)
408+ <*> o .: "ownerName"
409+ <*> o .: "ownerDomain"
410+ <*> o .:? "packagePath"
386411 <*> parseJSON (A.Object o)
387412
388413instance HasDescription (Service a) a where
@@ -390,130 +415,3 @@ instance HasDescription (Service a) a where
390415
391416urlName :: Service a -> Text
392417urlName = (<> "URL") . lowerHead . _sCanonicalName
393−
394−-- data Method a = Method
395−-- { _mId :: Text
396−-- , _mPath :: Text
397−-- , _mMethod :: Text
398−-- , _mDescription :: Maybe Help
399−-- , _mParameters :: Map Local (Param a)
400−-- , _mParameterOrder :: [Local]
401−-- , _mScopes :: [Text]
402−-- , _mRequest :: Maybe Global
403−-- , _mResponse :: Maybe Global
404−-- } deriving (Generic, Functor, Foldable, Traversable)
405−
406−-- instance FromJSON a => FromJSON (Method a) where
407−-- parseJSON = withObject "method" $ \o -> Method
408−-- <$> o .: "id"
409−-- <*> o .: "path"
410−-- <*> o .: "httpMethod"
411−-- <*> o .:? "description"
412−-- <*> o .:? "parameters" .!= mempty
413−-- <*> o .:? "parameterOrder" .!= mempty
414−-- <*> o .:? "scopes" .!= mempty
415−-- <*> ref o "request"
416−-- <*> ref o "response"
417−-- where
418−-- ref o k = Just <$> (o .: k >>= (.: "$ref"))
419−-- <|> pure Nothing
420−
421−-- data Resource a
422−-- = Top (Map Local (Resource a))
423−-- | Sub (Map Local (Method a))
424−-- deriving (Functor, Foldable, Traversable)
425−
426−-- instance FromJSON a => FromJSON (Resource a) where
427−-- parseJSON = withObject "resource" $ \o ->
428−-- Top <$> o .: "resources"
429−-- <|> Sub <$> o .: "methods"
430−
431−-- data Service s p r = Service
432−-- { _svcLibrary :: Text
433−-- , _svcTitle :: Text
434−-- , _svcName :: Text
435−-- , _svcCanonicalName :: Text
436−-- , _svcDescription :: Help
437−-- , _svcRevision :: Maybe Text
438−-- , _svcVersion :: Text
439−-- , _svcOwnerName :: Text
440−-- , _svcOwnerDomain :: Text
441−-- , _svcPackagePath :: Maybe Text
442−-- , _svcDocumentationLink :: Text
443−-- , _svcProtocol :: Protocol
444−-- , _svcBaseUrl :: Text
445−-- , _svcRootUrl :: Text
446−-- , _svcServicePath :: Text
447−-- , _svcBatchPath :: Text
448−-- , _svcAuth :: Maybe Object
449−-- , _svcParameters :: p
450−-- , _svcSchemas :: s
451−-- , _svcApi :: r
452−-- } deriving (Generic)
453−
454−-- type Parsed = Service (Map Id (Fix Schema))
455−-- (Map Local (Param (Fix Schema)))
456−-- (Resource (Fix Schema))
457−
458−-- type Flattened = Service [Id] [Param Id] (Resource Id)
459−-- type Typed = Service [Solved] [Param Solved] (Resource Solved)
460−-- type Printed = Service [Data] () API
461−
462−-- instance (FromJSON s, FromJSON p, FromJSON r) => FromJSON (Service s p r) where
463−-- parseJSON = withObject "service" $ \o -> Service
464−-- <$> o .: "library"
465−-- <*> o .: "title"
466−-- <*> o .: "name"
467−-- <*> o .: "canonicalName"
468−-- <*> o .: "description"
469−-- <*> o .:? "revision"
470−-- <*> o .: "version"
471−-- <*> o .: "ownerName"
472−-- <*> o .: "ownerDomain"
473−-- <*> o .:? "packagePath"
474−-- <*> o .: "documentationLink"
475−-- <*> o .: "protocol"
476−-- <*> o .: "baseUrl"
477−-- <*> o .: "rootUrl"
478−-- <*> o .: "servicePath"
479−-- <*> o .: "batchPath"
480−-- <*> o .:? "auth"
481−-- <*> o .: "parameters"
482−-- <*> o .: "schemas"
483−-- <*> parseJSON (Object o)
484−
485−-- instance (ToJSON s, ToJSON p) => ToJSON (Service s p API) where
486−-- toJSON s = Object (x <> y)
487−-- where
488−-- Object x = genericToJSON (js "_svc") s
489−-- Object y = object
490−-- [ "exposedModules" .= exposedModules s
491−-- ]
492−
493−-- type Parsed = Service (Map Id (Fix Schema))
494−-- (Map Local (Param (Fix Schema)))
495−-- (Resource (Fix Schema))
496−
497−-- type Flattened = Service [Id] [Param Id] (Resource Id)
498−-- type Typed = Service [Solved] [Param Solved] (Resource Solved)
499−-- type Printed = Service [Data] () API
500−
501−-- data Library = Library
502−-- { _libName :: Text
503−-- , _libTitle :: Text
504−-- , _libVersions :: Versions
505−-- , _libServices :: NonEmpty Printed
506−-- }
507−
508−-- instance ToJSON Library where
509−-- toJSON Library{..} = object
510−-- [ "libraryName" .= _libName
511−-- , "libraryTitle" .= _libTitle
512−-- , "libraryVersion" .= _libraryVersion _libVersions
513−-- , "libraryDescriptions" .= map (Desc 4 . _svcDescription) (NE.toList _libServices)
514−-- , "coreVersion" .= _coreVersion _libVersions
515−-- , "clientVersion" .= _clientVersion _libVersions
516−-- , "exposedModules" .= concatMap exposedModules (NE.toList _libServices)
517−-- , "otherModules" .= concatMap otherModules (NE.toList _libServices)
518−-- ]
519−
gen/template/action.ede+3−3
@@ -12,11 +12,11 @@
1212--
1313{{ action.type.help }}
1414--
15−-- /See:/ <{{ documentationLink }} {{ title }} Reference> for @{{ action.prettyName }}@.
15+-- /See:/ <{{ documentationLink }} {{ title }} Reference> for @{{ action.id }}@.
1616module {{ action.ns }}
1717 (
1818 -- * REST Resource
19− {{ action.name }}
19+ {{ action.aliasName }}
2020
2121 -- * Creating a Request
2222 , {{ action.type.ctor.name }}
@@ -34,7 +34,7 @@ module {{ action.ns }}
3434import {{ import.value }}
3535{% endfor %}
3636
37−-- | A resource alias for {{ action.prettyName }} which the
37+-- | A resource alias for @{{ action.id }}@ which the
3838-- '{{ action.type.name }}' request conforms to.
3939{{ action.alias }}
4040
gen/template/cabal.ede+1−3
@@ -14,9 +14,7 @@ cabal-version: >= 1.10
1414extra-source-files: README.md
1515
1616description:
17−{% for desc in libraryDescriptions %}
18−{{ desc.value }}
19−{% endfor %}
17+{{ libraryDescription }}
2018 .
2119 /Warning:/ This is an experimental prototype/preview release which is still
2220 under exploratory development and not intended for public use, caveat emptor!
gen/template/toc.ede+6−6
@@ -14,10 +14,10 @@ module {{ moduleName }}
1414 -- * REST Resources
1515
1616 -- ** {{ title }}
17− {{ api.name }}
18− , {{ api.name | lowerHead }}
17+ {{ api.aliasName }}
18+ , {{ api.aliasProxy }}
1919 , {{ api.url.name }}
20− {% for action in api.actions %}
20+ {% for action in api.methods %}
2121
2222 -- ** {{ action.value.prettyName }}
2323 , module {{ action.value.ns }}
@@ -55,7 +55,7 @@ import {{ module.value }}
5555TODO
5656-}
5757
58−{{ api.decl }}
58+{{ api.alias }}
5959
60−{{ api.name | lowerHead }} :: Proxy {{ api.name }}
61−{{ api.name | lowerHead }} = Proxy
60+{{ api.aliasProxy }} :: Proxy {{ api.aliasName }}
61+{{ api.aliasProxy }} = Proxy