@@ -36,6 +36,7 @@ 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
3940import Data.List.NonEmpty (NonEmpty (..))
4041import qualified Data.List.NonEmpty as NE
4142import Data.Maybe
@@ -301,6 +302,44 @@ instance ToJSON Data where
301302 , "lenses" .= ls
302303 ]
303304
305+data Method = Method
306+ { _mId :: Text
307+ , _mPath :: Text
308+ , _mMethod :: Text
309+ , _mDescription :: Help
310+ , _mParameters :: Map Id Param
311+ , _mParameterOrder :: [Id]
312+ , _mScopes :: [Text]
313+ , _mRequest :: Maybe Id
314+ , _mResponse :: Maybe Id
315+ } deriving (Generic)
316+
317+instance FromJSON Method where
318+ parseJSON = withObject "method" $ \o -> Method
319+ <$> o .: "id"
320+ <*> o .: "path"
321+ <*> o .: "httpMethod"
322+ <*> o .: "description"
323+ <*> o .: "parameters"
324+ <*> o .:? "parameterOrder" .!= mempty
325+ <*> o .: "scopes"
326+ <*> ref o "request"
327+ <*> ref o "response"
328+ where
329+ ref o k = Just <$> (o .: k >>= (.: "$ref"))
330+ <|> pure Nothing
331+
332+deriveToJSON (js "_m") ''Method
333+
334+newtype Resource = Resource { methods :: Map Id Method }
335+ deriving (ToJSON)
336+
337+deriveFromJSON (js "") ''Resource
338+
339+-- instance FromJSON Resource where
340+-- parseJSON = withObject "resource" $ \o ->
341+-- o .: "methods" -- <|> fail (show (Map.lookup "methods" o))
342+
304343data Service a = Service
305344 { _svcLibrary :: Text
306345 , _svcTitle :: Text
@@ -321,7 +360,7 @@ data Service a = Service
321360 , _svcAuth :: Maybe Object
322361 , _svcParameters :: Map Id Param
323362 , _svcSchemas :: Map Id a
324− , _svcResources :: Object
363+ , _svcResources :: Map Id Resource
325364 } deriving (Generic)
326365
327366deriveFromJSON (js "_svc") ''Service