@@ -1,6 +1,8 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE KindSignatures #-}
2{-# LANGUAGE KindSignatures #-}
3+{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE TemplateHaskell #-}
5-- Module : Gen.Types
7-- Module : Gen.Types
6-- Copyright : (c) 2015 Brendan Hay
8-- Copyright : (c) 2015 Brendan Hay
@@ -11,7 +13,10 @@
12module Gen.Types where
14module Gen.Types where
14import qualified Data.Attoparsec.Text as A
18import qualified Data.Attoparsec.Text as A
15import Data.Function (on)
20import Data.Function (on)
16import qualified Data.HashMap.Strict as Map
21import qualified Data.HashMap.Strict as Map
17import Data.List (nub, sort)
22import Data.List (nub, sort)
@@ -21,6 +26,7 @@ import Data.Text (Text)
21import qualified Data.Text as Text
26import qualified Data.Text as Text
22import qualified Data.Text.Lazy as LText
27import qualified Data.Text.Lazy as LText
23import qualified Filesystem.Path.CurrentOS as Path
28import qualified Filesystem.Path.CurrentOS as Path
24import GHC.TypeLits
30import GHC.TypeLits
25import Text.EDE (Template)
31import Text.EDE (Template)
@@ -69,12 +75,50 @@ instance Ord Spec where
69 <> on compare (Down . _specVersion) a b
75 <> on compare (Down . _specVersion) a b
71specFromPath :: Path -> Spec
77specFromPath :: Path -> Spec
72−specFromPath x = Spec (n <> v) p v x
78+specFromPath x = Spec n p v x
74− n = Text.intercalate "/"
82+ . Text.intercalate "/"
76 . dropWhile (/= "model")
84 . dropWhile (/= "model")
77 $ Text.split (== '/') p
85 $ Text.split (== '/') p
79 p = toTextIgnore (Path.parent (Path.parent x))
87 p = toTextIgnore (Path.parent (Path.parent x))
80 v = toTextIgnore (Path.dirname x)
88 v = toTextIgnore (Path.dirname x)
93+instance FromJSON Protocol where
94+ parseJSON = withText "protocol" $ \case
96+ e -> fail $ "Unable to parse protocol from " ++ Text.unpack e
98+data Service = Service
101+ , _svcDiscoveryVersion :: Text
104+ , _svcCanonicalName :: Maybe 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
124+deriveFromJSON (js "_svc") ''Service