@@ -34,8 +34,10 @@ import Control.Applicative
3434import Control.Lens hiding ((.=))
3535import Data.Aeson hiding (Bool, String)
3636import Data.Aeson.TH
37+import Data.Bifunctor
3738import Data.Char
3839import Data.Function (on)
40+import qualified Data.HashMap.Strict as Map
3941import Data.List.NonEmpty (NonEmpty (..))
4042import qualified Data.List.NonEmpty as NE
4143import Data.Maybe
@@ -125,8 +127,6 @@ specFromPath x = Spec n p v x
125127 p = toTextIgnore (Path.parent (Path.parent x))
126128 v = toTextIgnore (Path.dirname x)
127129
128−
129−
130130data Protocol = REST
131131 deriving (Eq, Show)
132132
@@ -257,14 +257,19 @@ instance HasInfo (Schema a) where
257257 Ref _ r -> Ref i r
258258 Any {} -> Any i
259259
260−data Param a = Param !Location !Bool a
261− deriving (Functor, Foldable, Traversable)
260+data Param = Param
261+ { _prmLocation :: !Location
262+ , _prmRepeated :: !Bool
263+ , _prmInfo :: Info
264+ , _prmLiteral :: !Lit
265+ }
262266
263−instance FromJSON a => FromJSON (Param a) where
267+instance FromJSON Param where
264268 parseJSON = withObject "parameter" $ \o -> Param
265269 <$> o .: "location"
266270 <*> o .:? "repeated" .!= False
267271 <*> parseJSON (Object o)
272+ <*> parseJSON (Object o)
268273
269274deriveToJSON (js "") ''Param
270275
@@ -305,63 +310,27 @@ instance ToJSON Data where
305310 , "lenses" .= ls
306311 ]
307312
308−
309−data TType
310− = TType Id
311− | TLit Lit
312− | TMaybe TType
313− | TEither TType TType
314− | TList TType
315−
316−data Derive
317− = DEq
318− | DOrd
319− | DRead
320− | DShow
321− | DEnum
322− | DNum
323− | DIntegral
324− | DReal
325− | DMonoid
326− | DIsString
327− | DData
328− | DTypeable
329− | DGeneric
330− deriving (Eq, Show)
331−
332−data Solved = Solved
333− { _schema :: Schema Id
334− , _type :: TType
335− , _deriving :: [Derive]
336− }
337−
338−instance HasInfo Solved where
339− info = f . info
340− where
341− f = lens _schema (\s a -> s { _schema = a })
342−
343−deriveToJSON (js "T") ''TType
344−deriveToJSON (js "D") ''Derive
345−deriveToJSON (js "_") ''Solved
346−
347−data API = API Name [Rendered]
313+data API = API Name (Map Name [Rendered])
348314
349315instance ToJSON API where
350− toJSON (API n d) = object ["name" .= Syn n, "types" .= d]
316+ toJSON (API n ms) = object
317+ [ "name" .= Syn n
318+ , "methods" .= Map.fromList (map (first prettyPrint) $ Map.toList ms)
319+ ]
351320
352−data Method a = Method
321+data Method = Method
353322 { _mId :: Text
354323 , _mPath :: Text
355324 , _mMethod :: Text
356325 , _mDescription :: Maybe Help
357− , _mParameters :: Map Id (Param a)
326+ , _mParameters :: Map Id Param
358327 , _mParameterOrder :: [Id]
359328 , _mScopes :: [Text]
360329 , _mRequest :: Maybe Id
361330 , _mResponse :: Maybe Id
362331 } deriving (Generic)
363332
364−instance FromJSON a => FromJSON (Method a) where
333+instance FromJSON Method where
365334 parseJSON = withObject "method" $ \o -> Method
366335 <$> o .: "id"
367336 <*> o .: "path"
@@ -378,11 +347,11 @@ instance FromJSON a => FromJSON (Method a) where
378347
379348deriveToJSON (js "_m") ''Method
380349
381−newtype Resource a = Resource { methods :: Map Id (Method a) }
350+newtype Resource = Resource { methods :: Map Id Method }
382351
383352deriveFromJSON (js "") ''Resource
384353
385−data Service s p r = Service
354+data Service s r = Service
386355 { _svcLibrary :: Text
387356 , _svcTitle :: Text
388357 , _svcName :: Text
@@ -400,14 +369,14 @@ data Service s p r = Service
400369 , _svcServicePath :: Text
401370 , _svcBatchPath :: Text
402371 , _svcAuth :: Maybe Object
403− , _svcParameters :: Map Id (Param p)
372+ , _svcParameters :: Map Id Param
404373 , _svcSchemas :: Map Id s
405374 , _svcResources :: Map Id r
406375 } deriving (Generic)
407376
408377deriveFromJSON (js "_svc") ''Service
409378
410−instance ToJSON p => ToJSON (Service Data p API) where
379+instance ToJSON (Service Data API) where
411380 toJSON s = Object (x <> y)
412381 where
413382 Object x = genericToJSON (js "_svc") s
@@ -416,24 +385,24 @@ instance ToJSON p => ToJSON (Service Data p API) where
416385 , "api" .= Syn (aname (idFromText (_svcName s)))
417386 ]
418387
419−svcAbbrev :: Service s p r -> Text
388+svcAbbrev :: Service s r -> Text
420389svcAbbrev = renameAbbrev . _svcTitle
421390
422−typeImports :: Service s p r -> [NS]
391+typeImports :: Service s r -> [NS]
423392typeImports _ = ["Network.Google.Prelude"]
424393
425−tocNS, typesNS :: Service s p r -> NS
394+tocNS, typesNS :: Service s r -> NS
426395tocNS s = NS ["Network", "Google", svcAbbrev s]
427396typesNS = (<> "Types") . tocNS
428397
429−exposedModules :: Service s p r -> [NS]
398+exposedModules :: Service s r -> [NS]
430399exposedModules s = [tocNS s, typesNS s]
431400
432401data Library = Library
433402 { _libName :: Text
434403 , _libTitle :: Text
435404 , _libVersions :: Versions
436− , _libServices :: NonEmpty (Service Data Solved API)
405+ , _libServices :: NonEmpty (Service Data API)
437406 }
438407
439408instance ToJSON Library where