@@ -18,7 +18,8 @@ module Gen.Types
18 , module Gen.Types.NS
18 , module Gen.Types.NS
21+import Control.Applicative
21−import Data.Aeson
22+import Data.Aeson hiding (String)
22import Data.Aeson.TH
23import Data.Aeson.TH
23import qualified Data.Attoparsec.Text as A
24import qualified Data.Attoparsec.Text as A
24import Data.Char
25import Data.Char
@@ -117,6 +118,66 @@ instance FromJSON Protocol where
117instance ToJSON Protocol where
118instance ToJSON Protocol where
118 toJSON = toJSON . map toLower . show
119 toJSON = toJSON . map toLower . show
126+deriveJSON (js "") ''Location
129+ { _infoDescription :: Maybe Text
130+ , _infoDefault :: Maybe Text
131+ } deriving (Eq, Show)
133+deriveJSON (js "_info") ''Info
140+deriveToJSON (js "") ''Lit
143+ = Obj Info (Map Text Schema)
145+ | Enum Info [Text] [Text]
148+ | Any' -- String or Number
151+instance FromJSON Schema where
152+ parseJSON = withObject "schema" $ \o -> schema o <|> ref o
155+ i <- parseJSON (Object o)
156+ t <- o .: "type" -- <|> fail ("Missing 'type' in " ++ show o)
158+ "object" -> Obj i <$> o .: "properties"
159+ "array" -> Arr i <$> o .: "items"
160+ "string" -> enum i o <|> pure (Lit i String)
161+ "boolean" -> pure (Lit i Boolean)
164+ "Unable to parse Schema from: '" ++ Text.unpack t ++ "'"
166+ enum i o = Enum i <$> o .: "enum" <*> o .: "enumDescriptions"
168+ ref o = Ref <$> o .: "$ref"
170+deriveToJSON (js "") ''Schema
172+data Param = Param Location Schema
175+instance FromJSON Param where
176+ parseJSON = withObject "parameter" $ \o ->
177+ Param <$> o .: "location" <*> parseJSON (Object o)
179+deriveToJSON (js "") ''Param
120data Service = Service
181data Service = Service
121 { _svcLibrary :: Text
182 { _svcLibrary :: Text
122 , _svcTitle :: Text
183 , _svcTitle :: Text
@@ -134,9 +195,10 @@ data Service = Service
134 , _svcRootUrl :: Text
195 , _svcRootUrl :: Text
135 , _svcServicePath :: Text
196 , _svcServicePath :: Text
136 , _svcBatchPath :: Text
197 , _svcBatchPath :: Text
137− , _svcParameters :: Object
138 , _svcAuth :: Maybe Object
198 , _svcAuth :: Maybe Object
199+ , _svcParameters :: Map Text Param
139− , _svcSchemas :: Object
200+ , _svcSchemas :: Map Text Schema
201+ , _svcResources :: Object
140 } deriving (Show, Generic)
202 } deriving (Show, Generic)
142deriveFromJSON (js "_svc") ''Service
204deriveFromJSON (js "_svc") ''Service