@@ -34,8 +34,10 @@ import Control.Applicative
34import Control.Lens hiding ((.=))
34import Control.Lens hiding ((.=))
35import Data.Aeson hiding (Bool, String)
35import Data.Aeson hiding (Bool, String)
36import Data.Aeson.TH
36import Data.Aeson.TH
37import Data.Char
38import Data.Char
38import Data.Function (on)
39import Data.Function (on)
40+import qualified Data.HashMap.Strict as Map
39import Data.List.NonEmpty (NonEmpty (..))
41import Data.List.NonEmpty (NonEmpty (..))
40import qualified Data.List.NonEmpty as NE
42import qualified Data.List.NonEmpty as NE
41import Data.Maybe
43import Data.Maybe
@@ -125,8 +127,6 @@ specFromPath x = Spec n p v x
125 p = toTextIgnore (Path.parent (Path.parent x))
127 p = toTextIgnore (Path.parent (Path.parent x))
126 v = toTextIgnore (Path.dirname x)
128 v = toTextIgnore (Path.dirname x)
130data Protocol = REST
130data Protocol = REST
131 deriving (Eq, Show)
131 deriving (Eq, Show)
@@ -257,14 +257,19 @@ 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 a = Param !Location !Bool a
260+data Param = Param
261− deriving (Functor, Foldable, Traversable)
261+ { _prmLocation :: !Location
262+ , _prmRepeated :: !Bool
264+ , _prmLiteral :: !Lit
263−instance FromJSON a => FromJSON (Param a) where
267+instance FromJSON Param where
264 parseJSON = withObject "parameter" $ \o -> Param
268 parseJSON = withObject "parameter" $ \o -> Param
265 <$> o .: "location"
269 <$> o .: "location"
266 <*> o .:? "repeated" .!= False
270 <*> o .:? "repeated" .!= False
267 <*> parseJSON (Object o)
271 <*> parseJSON (Object o)
272+ <*> parseJSON (Object o)
269deriveToJSON (js "") ''Param
274deriveToJSON (js "") ''Param
@@ -305,63 +310,27 @@ instance ToJSON Data where
305 , "lenses" .= ls
310 , "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]
313+data API = API Name (Map Name [Rendered])
349instance ToJSON API where
315instance ToJSON API where
350− toJSON (API n d) = object ["name" .= Syn n, "types" .= d]
316+ toJSON (API n ms) = object
318+ , "methods" .= Map.fromList (map (first prettyPrint) $ Map.toList ms)
352−data Method a = Method
321+data Method = Method
353 { _mId :: Text
322 { _mId :: Text
354 , _mPath :: Text
323 , _mPath :: Text
355 , _mMethod :: Text
324 , _mMethod :: Text
356 , _mDescription :: Maybe Help
325 , _mDescription :: Maybe Help
357− , _mParameters :: Map Id (Param a)
326+ , _mParameters :: Map Id Param
358 , _mParameterOrder :: [Id]
327 , _mParameterOrder :: [Id]
359 , _mScopes :: [Text]
328 , _mScopes :: [Text]
360 , _mRequest :: Maybe Id
329 , _mRequest :: Maybe Id
361 , _mResponse :: Maybe Id
330 , _mResponse :: Maybe Id
362 } deriving (Generic)
331 } deriving (Generic)
364−instance FromJSON a => FromJSON (Method a) where
333+instance FromJSON Method where
365 parseJSON = withObject "method" $ \o -> Method
334 parseJSON = withObject "method" $ \o -> Method
366 <$> o .: "id"
335 <$> o .: "id"
367 <*> o .: "path"
336 <*> o .: "path"
@@ -378,11 +347,11 @@ instance FromJSON a => FromJSON (Method a) where
379deriveToJSON (js "_m") ''Method
348deriveToJSON (js "_m") ''Method
381−newtype Resource a = Resource { methods :: Map Id (Method a) }
350+newtype Resource = Resource { methods :: Map Id Method }
383deriveFromJSON (js "") ''Resource
352deriveFromJSON (js "") ''Resource
385−data Service s p r = Service
354+data Service s r = Service
386 { _svcLibrary :: Text
355 { _svcLibrary :: Text
387 , _svcTitle :: Text
356 , _svcTitle :: Text
388 , _svcName :: Text
357 , _svcName :: Text
@@ -400,14 +369,14 @@ data Service s p r = Service
400 , _svcServicePath :: Text
369 , _svcServicePath :: Text
401 , _svcBatchPath :: Text
370 , _svcBatchPath :: Text
402 , _svcAuth :: Maybe Object
371 , _svcAuth :: Maybe Object
403− , _svcParameters :: Map Id (Param p)
372+ , _svcParameters :: Map Id Param
404 , _svcSchemas :: Map Id s
373 , _svcSchemas :: Map Id s
405 , _svcResources :: Map Id r
374 , _svcResources :: Map Id r
406 } deriving (Generic)
375 } deriving (Generic)
408deriveFromJSON (js "_svc") ''Service
377deriveFromJSON (js "_svc") ''Service
410−instance ToJSON p => ToJSON (Service Data p API) where
379+instance ToJSON (Service Data API) where
411 toJSON s = Object (x <> y)
380 toJSON s = Object (x <> y)
413 Object x = genericToJSON (js "_svc") s
382 Object x = genericToJSON (js "_svc") s
@@ -416,24 +385,24 @@ instance ToJSON p => ToJSON (Service Data p API) where
416 , "api" .= Syn (aname (idFromText (_svcName s)))
385 , "api" .= Syn (aname (idFromText (_svcName s)))
419−svcAbbrev :: Service s p r -> Text
388+svcAbbrev :: Service s r -> Text
420svcAbbrev = renameAbbrev . _svcTitle
389svcAbbrev = renameAbbrev . _svcTitle
422−typeImports :: Service s p r -> [NS]
391+typeImports :: Service s r -> [NS]
423typeImports _ = ["Network.Google.Prelude"]
392typeImports _ = ["Network.Google.Prelude"]
425−tocNS, typesNS :: Service s p r -> NS
394+tocNS, typesNS :: Service s r -> NS
426tocNS s = NS ["Network", "Google", svcAbbrev s]
395tocNS s = NS ["Network", "Google", svcAbbrev s]
427typesNS = (<> "Types") . tocNS
396typesNS = (<> "Types") . tocNS
429−exposedModules :: Service s p r -> [NS]
398+exposedModules :: Service s r -> [NS]
430exposedModules s = [tocNS s, typesNS s]
399exposedModules s = [tocNS s, typesNS s]
432data Library = Library
401data Library = Library
433 { _libName :: Text
402 { _libName :: Text
434 , _libTitle :: Text
403 , _libTitle :: Text
435 , _libVersions :: Versions
404 , _libVersions :: Versions
436− , _libServices :: NonEmpty (Service Data Solved API)
405+ , _libServices :: NonEmpty (Service Data API)
439instance ToJSON Library where
408instance ToJSON Library where