@@ -36,7 +36,6 @@ import Data.Aeson hiding (Bool, String)
3636import Data.Aeson.TH
3737import Data.Char
3838import Data.Function (on)
39−import qualified Data.HashMap.Strict as Map
4039import Data.List.NonEmpty (NonEmpty (..))
4140import qualified Data.List.NonEmpty as NE
4241import Data.Maybe
@@ -72,11 +71,10 @@ toTextIgnore :: Path -> Text
7271toTextIgnore = either id id . Path.toText
7372
7473data Templates = Templates
75− { cabalTemplate :: Template
76− , tocTemplate :: Template
77− , readmeTemplate :: Template
78− , operationTemplate :: Template
79− , typesTemplate :: Template
74+ { cabalTemplate :: Template
75+ , tocTemplate :: Template
76+ , readmeTemplate :: Template
77+ , typesTemplate :: Template
8078 }
8179
8280newtype Version (v :: Symbol) = Version Text
@@ -127,6 +125,8 @@ specFromPath x = Spec n p v x
127125 p = toTextIgnore (Path.parent (Path.parent x))
128126 v = toTextIgnore (Path.dirname x)
129127
128+
129+
130130data Protocol = REST
131131 deriving (Eq, Show)
132132
@@ -257,11 +257,14 @@ instance HasInfo (Schema a) where
257257 Ref _ r -> Ref i r
258258 Any {} -> Any i
259259
260−data Param = Param Location -- (Fix Schema)
260+data Param a = Param !Location !Bool a
261+ deriving (Functor, Foldable, Traversable)
261262
262−instance FromJSON Param where
263− parseJSON = withObject "parameter" $ \o ->
264− Param <$> o .: "location" -- <*> parseJSON (Object o)
263+instance FromJSON a => FromJSON (Param a) where
264+ parseJSON = withObject "parameter" $ \o -> Param
265+ <$> o .: "location"
266+ <*> o .:? "repeated" .!= False
267+ <*> parseJSON (Object o)
265268
266269deriveToJSON (js "") ''Param
267270
@@ -302,27 +305,71 @@ instance ToJSON Data where
302305 , "lenses" .= ls
303306 ]
304307
305−data Method = Method
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]
348+
349+instance ToJSON API where
350+ toJSON (API n d) = object ["name" .= Syn n, "types" .= d]
351+
352+data Method a = Method
306353 { _mId :: Text
307354 , _mPath :: Text
308355 , _mMethod :: Text
309− , _mDescription :: Help
310− , _mParameters :: Map Id Param
356+ , _mDescription :: Maybe Help
357+ , _mParameters :: Map Id (Param a)
311358 , _mParameterOrder :: [Id]
312359 , _mScopes :: [Text]
313360 , _mRequest :: Maybe Id
314361 , _mResponse :: Maybe Id
315362 } deriving (Generic)
316363
317−instance FromJSON Method where
364+instance FromJSON a => FromJSON (Method a) where
318365 parseJSON = withObject "method" $ \o -> Method
319366 <$> o .: "id"
320367 <*> o .: "path"
321368 <*> o .: "httpMethod"
322− <*> o .: "description"
369+ <*> o .:? "description"
323370 <*> o .: "parameters"
324371 <*> o .:? "parameterOrder" .!= mempty
325− <*> o .: "scopes"
372+ <*> o .:? "scopes" .!= mempty
326373 <*> ref o "request"
327374 <*> ref o "response"
328375 where
@@ -331,16 +378,11 @@ instance FromJSON Method where
331378
332379deriveToJSON (js "_m") ''Method
333380
334−newtype Resource = Resource { methods :: Map Id Method }
335− deriving (ToJSON)
381+newtype Resource a = Resource { methods :: Map Id (Method a) }
336382
337383deriveFromJSON (js "") ''Resource
338384
339−-- instance FromJSON Resource where
340−-- parseJSON = withObject "resource" $ \o ->
341−-- o .: "methods" -- <|> fail (show (Map.lookup "methods" o))
342−
343−data Service a = Service
385+data Service s p r = Service
344386 { _svcLibrary :: Text
345387 , _svcTitle :: Text
346388 , _svcName :: Text
@@ -358,39 +400,40 @@ data Service a = Service
358400 , _svcServicePath :: Text
359401 , _svcBatchPath :: Text
360402 , _svcAuth :: Maybe Object
361− , _svcParameters :: Map Id Param
362− , _svcSchemas :: Map Id a
363− , _svcResources :: Map Id Resource
403+ , _svcParameters :: Map Id (Param p)
404+ , _svcSchemas :: Map Id s
405+ , _svcResources :: Map Id r
364406 } deriving (Generic)
365407
366408deriveFromJSON (js "_svc") ''Service
367409
368−instance ToJSON (Service Data) where
410+instance ToJSON p => ToJSON (Service Data p API) where
369411 toJSON s = Object (x <> y)
370412 where
371413 Object x = genericToJSON (js "_svc") s
372414 Object y = object
373415 [ "exposedModules" .= exposedModules s
416+ , "api" .= Syn (aname (idFromText (_svcName s)))
374417 ]
375418
376−svcAbbrev :: Service a -> Text
419+svcAbbrev :: Service s p r -> Text
377420svcAbbrev = renameAbbrev . _svcTitle
378421
379−typeImports :: Service a -> [NS]
422+typeImports :: Service s p r -> [NS]
380423typeImports _ = ["Network.Google.Prelude"]
381424
382−tocNS, typesNS :: Service a -> NS
425+tocNS, typesNS :: Service s p r -> NS
383426tocNS s = NS ["Network", "Google", svcAbbrev s]
384427typesNS = (<> "Types") . tocNS
385428
386−exposedModules :: Service a -> [NS]
429+exposedModules :: Service s p r -> [NS]
387430exposedModules s = [tocNS s, typesNS s]
388431
389432data Library = Library
390433 { _libName :: Text
391434 , _libTitle :: Text
392435 , _libVersions :: Versions
393− , _libServices :: NonEmpty (Service Data)
436+ , _libServices :: NonEmpty (Service Data Solved API)
394437 }
395438
396439instance ToJSON Library where