@@ -36,7 +36,6 @@ import Data.Aeson hiding (Bool, String)
36import Data.Aeson.TH
36import Data.Aeson.TH
37import Data.Char
37import Data.Char
38import Data.Function (on)
38import Data.Function (on)
39−import qualified Data.HashMap.Strict as Map
40import Data.List.NonEmpty (NonEmpty (..))
39import Data.List.NonEmpty (NonEmpty (..))
41import qualified Data.List.NonEmpty as NE
40import qualified Data.List.NonEmpty as NE
42import Data.Maybe
41import Data.Maybe
@@ -72,11 +71,10 @@ toTextIgnore :: Path -> Text
72toTextIgnore = either id id . Path.toText
71toTextIgnore = either id id . Path.toText
74data Templates = Templates
73data Templates = Templates
75− { cabalTemplate :: Template
74+ { cabalTemplate :: Template
76− , tocTemplate :: Template
75+ , tocTemplate :: Template
77− , readmeTemplate :: Template
76+ , readmeTemplate :: Template
78− , operationTemplate :: Template
79− , typesTemplate :: Template
77+ , typesTemplate :: Template
82newtype Version (v :: Symbol) = Version Text
80newtype Version (v :: Symbol) = Version Text
@@ -127,6 +125,8 @@ specFromPath x = Spec n p v x
127 p = toTextIgnore (Path.parent (Path.parent x))
125 p = toTextIgnore (Path.parent (Path.parent x))
128 v = toTextIgnore (Path.dirname x)
126 v = toTextIgnore (Path.dirname x)
130data Protocol = REST
130data Protocol = REST
131 deriving (Eq, Show)
131 deriving (Eq, Show)
@@ -257,11 +257,14 @@ instance HasInfo (Schema a) where
257 Ref _ r -> Ref i r
257 Ref _ r -> Ref i r
258 Any {} -> Any i
258 Any {} -> Any i
260−data Param = Param Location -- (Fix Schema)
260+data Param a = Param !Location !Bool a
261+ deriving (Functor, Foldable, Traversable)
262−instance FromJSON Param where
263+instance FromJSON a => FromJSON (Param a) where
263− parseJSON = withObject "parameter" $ \o ->
264+ parseJSON = withObject "parameter" $ \o -> Param
266+ <*> o .:? "repeated" .!= False
264− Param <$> o .: "location" -- <*> parseJSON (Object o)
267+ <*> parseJSON (Object o)
266deriveToJSON (js "") ''Param
269deriveToJSON (js "") ''Param
@@ -302,27 +305,71 @@ instance ToJSON Data where
302 , "lenses" .= ls
305 , "lenses" .= ls
313+ | TEither TType TType
333+ { _schema :: Schema Id
335+ , _deriving :: [Derive]
338+instance HasInfo Solved where
341+ f = lens _schema (\s a -> s { _schema = a })
343+deriveToJSON (js "T") ''TType
344+deriveToJSON (js "D") ''Derive
345+deriveToJSON (js "_") ''Solved
347+data API = API Name [Rendered]
349+instance ToJSON API where
350+ toJSON (API n d) = object ["name" .= Syn n, "types" .= d]
305−data Method = Method
352+data Method a = Method
306 { _mId :: Text
353 { _mId :: Text
307 , _mPath :: Text
354 , _mPath :: Text
308 , _mMethod :: Text
355 , _mMethod :: Text
309− , _mDescription :: Help
356+ , _mDescription :: Maybe Help
310− , _mParameters :: Map Id Param
357+ , _mParameters :: Map Id (Param a)
311 , _mParameterOrder :: [Id]
358 , _mParameterOrder :: [Id]
312 , _mScopes :: [Text]
359 , _mScopes :: [Text]
313 , _mRequest :: Maybe Id
360 , _mRequest :: Maybe Id
314 , _mResponse :: Maybe Id
361 , _mResponse :: Maybe Id
315 } deriving (Generic)
362 } deriving (Generic)
317−instance FromJSON Method where
364+instance FromJSON a => FromJSON (Method a) where
318 parseJSON = withObject "method" $ \o -> Method
365 parseJSON = withObject "method" $ \o -> Method
319 <$> o .: "id"
366 <$> o .: "id"
320 <*> o .: "path"
367 <*> o .: "path"
321 <*> o .: "httpMethod"
368 <*> o .: "httpMethod"
322− <*> o .: "description"
369+ <*> o .:? "description"
323 <*> o .: "parameters"
370 <*> o .: "parameters"
324 <*> o .:? "parameterOrder" .!= mempty
371 <*> o .:? "parameterOrder" .!= mempty
325− <*> o .: "scopes"
372+ <*> o .:? "scopes" .!= mempty
326 <*> ref o "request"
373 <*> ref o "request"
327 <*> ref o "response"
374 <*> ref o "response"
@@ -331,16 +378,11 @@ instance FromJSON Method where
332deriveToJSON (js "_m") ''Method
379deriveToJSON (js "_m") ''Method
334−newtype Resource = Resource { methods :: Map Id Method }
381+newtype Resource a = Resource { methods :: Map Id (Method a) }
337deriveFromJSON (js "") ''Resource
383deriveFromJSON (js "") ''Resource
339−-- instance FromJSON Resource where
340−-- parseJSON = withObject "resource" $ \o ->
341−-- o .: "methods" -- <|> fail (show (Map.lookup "methods" o))
343−data Service a = Service
385+data Service s p r = Service
344 { _svcLibrary :: Text
386 { _svcLibrary :: Text
345 , _svcTitle :: Text
387 , _svcTitle :: Text
346 , _svcName :: Text
388 , _svcName :: Text
@@ -358,39 +400,40 @@ data Service a = Service
358 , _svcServicePath :: Text
400 , _svcServicePath :: Text
359 , _svcBatchPath :: Text
401 , _svcBatchPath :: Text
360 , _svcAuth :: Maybe Object
402 , _svcAuth :: Maybe Object
361− , _svcParameters :: Map Id Param
403+ , _svcParameters :: Map Id (Param p)
362− , _svcSchemas :: Map Id a
404+ , _svcSchemas :: Map Id s
363− , _svcResources :: Map Id Resource
405+ , _svcResources :: Map Id r
364 } deriving (Generic)
406 } deriving (Generic)
366deriveFromJSON (js "_svc") ''Service
408deriveFromJSON (js "_svc") ''Service
368−instance ToJSON (Service Data) where
410+instance ToJSON p => ToJSON (Service Data p API) where
369 toJSON s = Object (x <> y)
411 toJSON s = Object (x <> y)
371 Object x = genericToJSON (js "_svc") s
413 Object x = genericToJSON (js "_svc") s
372 Object y = object
414 Object y = object
373 [ "exposedModules" .= exposedModules s
415 [ "exposedModules" .= exposedModules s
416+ , "api" .= Syn (aname (idFromText (_svcName s)))
376−svcAbbrev :: Service a -> Text
419+svcAbbrev :: Service s p r -> Text
377svcAbbrev = renameAbbrev . _svcTitle
420svcAbbrev = renameAbbrev . _svcTitle
379−typeImports :: Service a -> [NS]
422+typeImports :: Service s p r -> [NS]
380typeImports _ = ["Network.Google.Prelude"]
423typeImports _ = ["Network.Google.Prelude"]
382−tocNS, typesNS :: Service a -> NS
425+tocNS, typesNS :: Service s p r -> NS
383tocNS s = NS ["Network", "Google", svcAbbrev s]
426tocNS s = NS ["Network", "Google", svcAbbrev s]
384typesNS = (<> "Types") . tocNS
427typesNS = (<> "Types") . tocNS
386−exposedModules :: Service a -> [NS]
429+exposedModules :: Service s p r -> [NS]
387exposedModules s = [tocNS s, typesNS s]
430exposedModules s = [tocNS s, typesNS s]
389data Library = Library
432data Library = Library
390 { _libName :: Text
433 { _libName :: Text
391 , _libTitle :: Text
434 , _libTitle :: Text
392 , _libVersions :: Versions
435 , _libVersions :: Versions
393− , _libServices :: NonEmpty (Service Data)
436+ , _libServices :: NonEmpty (Service Data Solved API)
396instance ToJSON Library where
439instance ToJSON Library where