git.iko.soy/typeable/swagger2
on master help sign in
Merge pull request #25 from GetShopTV/no-aeson-th
a6ac15fNickolay Kudasov
src/Data/Swagger/Internal.hs+61−14
@@ -9,14 +9,12 @@
9{-# LANGUAGE RecordWildCards #-}
9{-# LANGUAGE RecordWildCards #-}
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE StandaloneDeriving #-}
11{-# LANGUAGE StandaloneDeriving #-}
12−{-# LANGUAGE TemplateHaskell #-}
13{-# LANGUAGE UndecidableInstances #-}
12{-# LANGUAGE UndecidableInstances #-}
14module Data.Swagger.Internal where
13module Data.Swagger.Internal where
15
14
16import Control.Applicative
15import Control.Applicative
17import Control.Monad
16import Control.Monad
18import Data.Aeson
17import Data.Aeson
19−import Data.Aeson.TH (deriveJSON)
20import qualified Data.Aeson.Types as JSON
18import qualified Data.Aeson.Types as JSON
21import Data.Data (Data(..), Typeable, mkConstr, mkDataType, Fixity(..), Constr, DataType, constrIndex)
19import Data.Data (Data(..), Typeable, mkConstr, mkDataType, Fixity(..), Constr, DataType, constrIndex)
22import Data.HashMap.Strict (HashMap)
20import Data.HashMap.Strict (HashMap)
@@ -825,20 +823,69 @@ instance SwaggerMonoid ParamAnySchema where
825 swaggerMappend _ y = y
823 swaggerMappend _ y = y
826
824
827-- =======================================================================
825-- =======================================================================
828−-- TH derived ToJSON and FromJSON instances
826+-- Simple Generic-based ToJSON instances
829-- =======================================================================
827-- =======================================================================
830
828
829+instance ToJSON ParamLocation where
831−deriveJSON (jsonPrefix "Param") ''ParamLocation
830+ toJSON = genericToJSON (jsonPrefix "Param")
832−deriveJSON' ''Info
831+
833−deriveJSON' ''Contact
832+instance ToJSON Info where
834−deriveJSON' ''License
833+ toJSON = genericToJSON (jsonPrefix "Info")
835−deriveJSON (jsonPrefix "ApiKey") ''ApiKeyLocation
834+
836−deriveJSON (jsonPrefix "apiKey") ''ApiKeyParams
835+instance ToJSON Contact where
837−deriveJSONDefault ''Scheme
836+ toJSON = genericToJSON (jsonPrefix "Contact")
838−deriveJSON' ''Tag
837+
838+instance ToJSON License where
839+ toJSON = genericToJSON (jsonPrefix "License")
840+
841+instance ToJSON ApiKeyLocation where
842+ toJSON = genericToJSON (jsonPrefix "ApiKey")
843+
844+instance ToJSON ApiKeyParams where
845+ toJSON = genericToJSON (jsonPrefix "apiKey")
846+
847+instance ToJSON Scheme where
848+ toJSON = genericToJSON (jsonPrefix "")
849+
850+instance ToJSON Tag where
851+ toJSON = genericToJSON (jsonPrefix "Tag")
852+
839−deriveJSON' ''ExternalDocs
853+instance ToJSON ExternalDocs where
840−
854+ toJSON = genericToJSON (jsonPrefix "ExternalDocs")
841−deriveToJSON' ''Xml
855+
856+instance ToJSON Xml where
857+ toJSON = genericToJSON (jsonPrefix "Xml")
858+
859+-- =======================================================================
860+-- Simple Generic-based FromJSON instances
861+-- =======================================================================
862+
863+instance FromJSON ParamLocation where
864+ parseJSON = genericParseJSON (jsonPrefix "Param")
865+
866+instance FromJSON Info where
867+ parseJSON = genericParseJSON (jsonPrefix "Info")
868+
869+instance FromJSON Contact where
870+ parseJSON = genericParseJSON (jsonPrefix "Contact")
871+
872+instance FromJSON License where
873+ parseJSON = genericParseJSON (jsonPrefix "License")
874+
875+instance FromJSON ApiKeyLocation where
876+ parseJSON = genericParseJSON (jsonPrefix "ApiKey")
877+
878+instance FromJSON ApiKeyParams where
879+ parseJSON = genericParseJSON (jsonPrefix "apiKey")
880+
881+instance FromJSON Scheme where
882+ parseJSON = genericParseJSON (jsonPrefix "")
883+
884+instance FromJSON Tag where
885+ parseJSON = genericParseJSON (jsonPrefix "Tag")
886+
887+instance FromJSON ExternalDocs where
888+ parseJSON = genericParseJSON (jsonPrefix "ExternalDocs")
842
889
843-- =======================================================================
890-- =======================================================================
844-- Manual ToJSON instances
891-- Manual ToJSON instances
src/Data/Swagger/Internal/Utils.hs+1−12
@@ -8,8 +8,7 @@ module Data.Swagger.Internal.Utils where
8import Control.Arrow (first)
8import Control.Arrow (first)
9import Control.Applicative
9import Control.Applicative
10import Data.Aeson
10import Data.Aeson
11−import Data.Aeson.TH
11+import Data.Aeson.Types
12−import Data.Aeson.Types (Parser, Pair)
13import Data.Char
12import Data.Char
14import Data.Data
13import Data.Data
15import Data.Hashable (Hashable)
14import Data.Hashable (Hashable)
@@ -18,7 +17,6 @@ import qualified Data.HashMap.Strict as HashMap
18import Data.Monoid
17import Data.Monoid
19import Data.Text (Text)
18import Data.Text (Text)
20import GHC.Generics
19import GHC.Generics
21−import Language.Haskell.TH
22import Text.Read (readMaybe)
20import Text.Read (readMaybe)
23
21
24gunfoldEnum :: String -> [a] -> (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
22gunfoldEnum :: String -> [a] -> (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
@@ -50,15 +48,6 @@ jsonPrefix prefix = defaultOptions
50 lowerFirstUppers s = map toLower x ++ y
48 lowerFirstUppers s = map toLower x ++ y
51 where (x, y) = span isUpper s
49 where (x, y) = span isUpper s
52
50
53−deriveToJSON' :: Name -> Q [Dec]
54−deriveToJSON' name = deriveToJSON (jsonPrefix (nameBase name)) name
55−
56−deriveJSONDefault :: Name -> Q [Dec]
57−deriveJSONDefault = deriveJSON (jsonPrefix "")
58−
59−deriveJSON' :: Name -> Q [Dec]
60−deriveJSON' name = deriveJSON (jsonPrefix (nameBase name)) name
61−
62parseOneOf :: ToJSON a => [a] -> Value -> Parser a
51parseOneOf :: ToJSON a => [a] -> Value -> Parser a
63parseOneOf xs js =
52parseOneOf xs js =
64 case lookup js ys of
53 case lookup js ys of
swagger2.cabal+1−2
@@ -32,13 +32,12 @@ library
32 Data.Swagger.Internal.ParamSchema
32 Data.Swagger.Internal.ParamSchema
33 Data.Swagger.Internal.Utils
33 Data.Swagger.Internal.Utils
34 build-depends: base == 4.*
34 build-depends: base == 4.*
35− , aeson < 0.10
35+ , aeson
36 , containers
36 , containers
37 , hashable
37 , hashable
38 , http-media
38 , http-media
39 , mtl
39 , mtl
40 , network
40 , network
41− , template-haskell
42 , text
41 , text
43 , time
42 , time
44 , unordered-containers
43 , unordered-containers