@@ -1,6 +1,8 @@
11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE KindSignatures #-}
3+{-# LANGUAGE LambdaCase #-}
34{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE TemplateHaskell #-}
46
57-- Module : Gen.Types
68-- Copyright : (c) 2015 Brendan Hay
@@ -11,7 +13,10 @@
1113
1214module Gen.Types where
1315
16+import Data.Aeson
17+import Data.Aeson.TH
1418import qualified Data.Attoparsec.Text as A
19+import Data.Char
1520import Data.Function (on)
1621import qualified Data.HashMap.Strict as Map
1722import Data.List (nub, sort)
@@ -21,6 +26,7 @@ import Data.Text (Text)
2126import qualified Data.Text as Text
2227import qualified Data.Text.Lazy as LText
2328import qualified Filesystem.Path.CurrentOS as Path
29+import Gen.JSON
2430import GHC.TypeLits
2531import Text.EDE (Template)
2632
@@ -69,12 +75,50 @@ instance Ord Spec where
6975 <> on compare (Down . _specVersion) a b
7076
7177specFromPath :: Path -> Spec
72−specFromPath x = Spec (n <> v) p v x
78+specFromPath x = Spec n p v x
7379 where
74− n = Text.intercalate "/"
75− . drop 1
80+ -- FIXME:
81+ n = Text.init
82+ . Text.intercalate "/"
83+ . drop 2
7684 . dropWhile (/= "model")
7785 $ Text.split (== '/') p
7886
7987 p = toTextIgnore (Path.parent (Path.parent x))
8088 v = toTextIgnore (Path.dirname x)
89+
90+data Protocol = REST
91+ deriving (Eq, Show)
92+
93+instance FromJSON Protocol where
94+ parseJSON = withText "protocol" $ \case
95+ "rest" -> pure REST
96+ e -> fail $ "Unable to parse protocol from " ++ Text.unpack e
97+
98+data Service = Service
99+ { _svcKind :: Text
100+ , _svcEtag :: Text
101+ , _svcDiscoveryVersion :: Text
102+ , _svcId :: Text
103+ , _svcName :: Text
104+ , _svcCanonicalName :: Maybe Text
105+ , _svcTitle :: Text
106+ , _svcVersion :: Text
107+ , _svcRevision :: Maybe Text
108+ , _svcDescription :: Text
109+ , _svcOwnerDomain :: Text
110+ , _svcOwnerName :: Text
111+ , _svcPackagePath :: Maybe Text
112+ , _svcIcons :: Object
113+ , _svcDocumentationLink :: Text
114+ , _svcProtocol :: Protocol
115+ , _svcBaseUrl :: Text
116+ , _svcRootUrl :: Text
117+ , _svcServicePath :: Text
118+ , _svcBatchPath :: Text
119+ , _svcParameters :: Object
120+ , _svcAuth :: Maybe Object
121+ , _svcSchemas :: Object
122+ } deriving (Show)
123+
124+deriveFromJSON (js "_svc") ''Service