@@ -98,7 +98,7 @@ makeClassy ''Info
9898
9999instance FromJSON Info where
100100 parseJSON = withObject "info" $ \o -> Info
101− <$> o .: "id"
101+ <$> o .:? "id"
102102 <*> o .:? "description"
103103 <*> o .:? "default"
104104 <*> o .:? "required" .!= False
@@ -137,6 +137,7 @@ instance HasInfo (Schema a) where
137137 info = lens f (flip g)
138138 where
139139 f = \case
140+ SAny i _ -> i
140141 SRef i _ -> i
141142 SLit i _ -> i
142143 SEnm i _ -> i
@@ -144,6 +145,7 @@ instance HasInfo (Schema a) where
144145 SObj i _ -> i
145146
146147 g i = \case
148+ SAny _ x -> SAny i x
147149 SRef _ x -> SRef i x
148150 SLit _ x -> SLit i x
149151 SEnm _ x -> SEnm i x
@@ -155,6 +157,7 @@ checkType x o = do
155157 y <- o .: "type"
156158 unless (x == y) . fail . Text.unpack $
157159 "Schema type mismatch, expected " <> x <> ", but got " <> y
160+ <> "\n" <> Text.pack (show o)
158161
159162data Any = Any
160163 deriving (Eq, Show)
@@ -221,7 +224,7 @@ newtype Arr a = Arr { _aItem :: a }
221224instance FromJSON a => FromJSON (Arr a) where
222225 parseJSON = withObject "array" $ \o -> do
223226 checkType "array" o
224− Arr <$> o .: "item"
227+ Arr <$> o .: "items"
225228
226229data Obj a = Obj
227230 { _oAdditional :: Maybe a
@@ -284,7 +287,7 @@ instance FromJSON a => FromJSON (Method a) where
284287 <$> o .: "id"
285288 <*> o .: "path"
286289 <*> o .: "httpMethod"
287− <*> o .: "description"
290+ <*> o .:? "description"
288291 <*> o .:? "parameters" .!= mempty
289292 <*> o .:? "parameterOrder" .!= mempty
290293 <*> o .:? "request"
@@ -305,13 +308,35 @@ instance FromJSON a => FromJSON (Resource a) where
305308 <$> o .:? "resources" .!= mempty
306309 <*> (o .:? "methods" .!= mempty <&> keyless)
307310
308−newtype OAuth2 = OAuth2 { scopes :: Map Text Text }
311+newtype OAuth2 = OAuth2 { scopes :: Map Text Help }
309312 deriving (Eq, Show)
310313
311314instance FromJSON OAuth2 where
312− parseJSON = withObject "oauth2" $ \o ->
313− o .: "oauth2" >>=
314− withObject "scopes" (.: "scopes")
315+ parseJSON = withObject "oauth2" $ \x -> do
316+ y <- x .: "oauth2"
317+ z <- y .: "scopes"
318+ OAuth2 <$> traverse (.: "description") z
319+
320+data Label
321+ = Deprecated
322+ | LimitedAvailability
323+ | Labs
324+ deriving (Eq, Show)
325+
326+instance FromJSON Label where
327+ parseJSON = withText "label" $ \t ->
328+ case t of
329+ "deprecated" -> pure Deprecated
330+ "limited_availability" -> pure LimitedAvailability
331+ "labs" -> pure Labs
332+ _ -> fail $
333+ Text.unpack ("Unable to parse Label from: " <> t)
334+
335+instance ToJSON Label where
336+ toJSON = toJSON . \case
337+ Deprecated -> "deprecated" :: Text
338+ LimitedAvailability -> "limited_availability"
339+ Labs -> "labs"
315340
316341data Description a = Description
317342 { _dKind :: Text
@@ -324,14 +349,14 @@ data Description a = Description
324349 , _dDescription :: Help
325350 , _dIcons :: Map Text Text
326351 , _dDocumentationLink :: Text
327− , _dLabels :: Text
352+ , _dLabels :: [Label]
328353 , _dProtocol :: Text
329354 , _dBaseUrl :: Text
330355 , _dRootUrl :: Text
331356 , _dServicePath :: Text
332357 , _dBatchPath :: Text
333358 , _dParameters :: Map Local (Param a)
334− , _dAuth :: OAuth2
359+ , _dAuth :: Maybe OAuth2
335360 , _dFeatures :: [Text]
336361 , _dSchemas :: Map Global a
337362 , _dResources :: Map Global (Resource a)
@@ -352,14 +377,14 @@ instance FromJSON a => FromJSON (Description a) where
352377 <*> o .: "description"
353378 <*> o .: "icons"
354379 <*> o .: "documentationLink"
355− <*> o .: "labels"
380+ <*> o .:? "labels" .!= mempty
356381 <*> o .: "protocol"
357382 <*> o .: "baseUrl"
358383 <*> o .: "rootUrl"
359384 <*> o .: "servicePath"
360385 <*> o .: "batchPath"
361386 <*> o .:? "parameters" .!= mempty
362− <*> o .: "auth"
387+ <*> o .:? "auth"
363388 <*> o .:? "features" .!= mempty
364389 <*> o .:? "schemas" .!= mempty
365390 <*> o .:? "resources" .!= mempty
@@ -378,11 +403,11 @@ makeClassy ''Service
378403
379404instance FromJSON a => FromJSON (Service a) where
380405 parseJSON = withObject "service" $ \o -> Service
381− <$> o .: "library"
382− <*> (o .: "canonicalName" <&> upperHead . renameAbbrev)
383− <*> o .: "ownerName"
384− <*> o .: "ownerDomain"
385− <*> o .: "packagePath"
406+ <$> o .: "library"
407+ <*> (o .: "canonicalName" <&> upperHead . renameAbbrev)
408+ <*> o .: "ownerName"
409+ <*> o .: "ownerDomain"
410+ <*> o .:? "packagePath"
386411 <*> parseJSON (A.Object o)
387412
388413instance HasDescription (Service a) a where
@@ -390,130 +415,3 @@ instance HasDescription (Service a) a where
390415
391416urlName :: Service a -> Text
392417urlName = (<> "URL") . lowerHead . _sCanonicalName
393−
394−-- data Method a = Method
395−-- { _mId :: Text
396−-- , _mPath :: Text
397−-- , _mMethod :: Text
398−-- , _mDescription :: Maybe Help
399−-- , _mParameters :: Map Local (Param a)
400−-- , _mParameterOrder :: [Local]
401−-- , _mScopes :: [Text]
402−-- , _mRequest :: Maybe Global
403−-- , _mResponse :: Maybe Global
404−-- } deriving (Generic, Functor, Foldable, Traversable)
405−
406−-- instance FromJSON a => FromJSON (Method a) where
407−-- parseJSON = withObject "method" $ \o -> Method
408−-- <$> o .: "id"
409−-- <*> o .: "path"
410−-- <*> o .: "httpMethod"
411−-- <*> o .:? "description"
412−-- <*> o .:? "parameters" .!= mempty
413−-- <*> o .:? "parameterOrder" .!= mempty
414−-- <*> o .:? "scopes" .!= mempty
415−-- <*> ref o "request"
416−-- <*> ref o "response"
417−-- where
418−-- ref o k = Just <$> (o .: k >>= (.: "$ref"))
419−-- <|> pure Nothing
420−
421−-- data Resource a
422−-- = Top (Map Local (Resource a))
423−-- | Sub (Map Local (Method a))
424−-- deriving (Functor, Foldable, Traversable)
425−
426−-- instance FromJSON a => FromJSON (Resource a) where
427−-- parseJSON = withObject "resource" $ \o ->
428−-- Top <$> o .: "resources"
429−-- <|> Sub <$> o .: "methods"
430−
431−-- data Service s p r = Service
432−-- { _svcLibrary :: Text
433−-- , _svcTitle :: Text
434−-- , _svcName :: Text
435−-- , _svcCanonicalName :: Text
436−-- , _svcDescription :: Help
437−-- , _svcRevision :: Maybe Text
438−-- , _svcVersion :: Text
439−-- , _svcOwnerName :: Text
440−-- , _svcOwnerDomain :: Text
441−-- , _svcPackagePath :: Maybe Text
442−-- , _svcDocumentationLink :: Text
443−-- , _svcProtocol :: Protocol
444−-- , _svcBaseUrl :: Text
445−-- , _svcRootUrl :: Text
446−-- , _svcServicePath :: Text
447−-- , _svcBatchPath :: Text
448−-- , _svcAuth :: Maybe Object
449−-- , _svcParameters :: p
450−-- , _svcSchemas :: s
451−-- , _svcApi :: r
452−-- } deriving (Generic)
453−
454−-- type Parsed = Service (Map Id (Fix Schema))
455−-- (Map Local (Param (Fix Schema)))
456−-- (Resource (Fix Schema))
457−
458−-- type Flattened = Service [Id] [Param Id] (Resource Id)
459−-- type Typed = Service [Solved] [Param Solved] (Resource Solved)
460−-- type Printed = Service [Data] () API
461−
462−-- instance (FromJSON s, FromJSON p, FromJSON r) => FromJSON (Service s p r) where
463−-- parseJSON = withObject "service" $ \o -> Service
464−-- <$> o .: "library"
465−-- <*> o .: "title"
466−-- <*> o .: "name"
467−-- <*> o .: "canonicalName"
468−-- <*> o .: "description"
469−-- <*> o .:? "revision"
470−-- <*> o .: "version"
471−-- <*> o .: "ownerName"
472−-- <*> o .: "ownerDomain"
473−-- <*> o .:? "packagePath"
474−-- <*> o .: "documentationLink"
475−-- <*> o .: "protocol"
476−-- <*> o .: "baseUrl"
477−-- <*> o .: "rootUrl"
478−-- <*> o .: "servicePath"
479−-- <*> o .: "batchPath"
480−-- <*> o .:? "auth"
481−-- <*> o .: "parameters"
482−-- <*> o .: "schemas"
483−-- <*> parseJSON (Object o)
484−
485−-- instance (ToJSON s, ToJSON p) => ToJSON (Service s p API) where
486−-- toJSON s = Object (x <> y)
487−-- where
488−-- Object x = genericToJSON (js "_svc") s
489−-- Object y = object
490−-- [ "exposedModules" .= exposedModules s
491−-- ]
492−
493−-- type Parsed = Service (Map Id (Fix Schema))
494−-- (Map Local (Param (Fix Schema)))
495−-- (Resource (Fix Schema))
496−
497−-- type Flattened = Service [Id] [Param Id] (Resource Id)
498−-- type Typed = Service [Solved] [Param Solved] (Resource Solved)
499−-- type Printed = Service [Data] () API
500−
501−-- data Library = Library
502−-- { _libName :: Text
503−-- , _libTitle :: Text
504−-- , _libVersions :: Versions
505−-- , _libServices :: NonEmpty Printed
506−-- }
507−
508−-- instance ToJSON Library where
509−-- toJSON Library{..} = object
510−-- [ "libraryName" .= _libName
511−-- , "libraryTitle" .= _libTitle
512−-- , "libraryVersion" .= _libraryVersion _libVersions
513−-- , "libraryDescriptions" .= map (Desc 4 . _svcDescription) (NE.toList _libServices)
514−-- , "coreVersion" .= _coreVersion _libVersions
515−-- , "clientVersion" .= _clientVersion _libVersions
516−-- , "exposedModules" .= concatMap exposedModules (NE.toList _libServices)
517−-- , "otherModules" .= concatMap otherModules (NE.toList _libServices)
518−-- ]
519−