@@ -1,5 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2−{-# LANGUAGE DeriveAnyClass #-}
3{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE PackageImports #-}
3{-# LANGUAGE PackageImports #-}
5module Data.Swagger.Schema.ValidationSpec where
4module Data.Swagger.Schema.ValidationSpec where
@@ -91,7 +90,14 @@ main = hspec spec
91-- ========================================================================
90-- ========================================================================
92-- Person (simple record with optional fields)
91-- Person (simple record with optional fields)
93-- ========================================================================
92-- ========================================================================
94−data Person = Person { name :: String , phone :: Integer , email :: Maybe String } deriving (Show, Generic, ToSchema, ToJSON)
93+data Person = Person
96+ , email :: Maybe String
97+ } deriving (Show, Generic)
99+instance ToJSON Person
100+instance ToSchema Person
96instance Arbitrary Person where
102instance Arbitrary Person where
97 arbitrary = Person <$> arbitrary <*> arbitrary <*> arbitrary
103 arbitrary = Person <$> arbitrary <*> arbitrary <*> arbitrary
@@ -99,7 +105,10 @@ instance Arbitrary Person where
99-- ========================================================================
105-- ========================================================================
100-- Color (enum)
106-- Color (enum)
101-- ========================================================================
107-- ========================================================================
102−data Color = Red | Green | Blue deriving (Show, Generic, ToSchema, ToJSON, Bounded, Enum)
108+data Color = Red | Green | Blue deriving (Show, Generic, Bounded, Enum)
110+instance ToJSON Color
111+instance ToSchema Color
104instance Arbitrary Color where
113instance Arbitrary Color where
105 arbitrary = arbitraryBoundedEnum
114 arbitrary = arbitraryBoundedEnum
@@ -109,7 +118,10 @@ instance Arbitrary Color where
109-- ========================================================================
118-- ========================================================================
111newtype Paint = Paint { color :: Color }
120newtype Paint = Paint { color :: Color }
112− deriving (Show, Generic, ToSchema, ToJSON)
121+ deriving (Show, Generic)
123+instance ToJSON Paint
124+instance ToSchema Paint
114instance Arbitrary Paint where
126instance Arbitrary Paint where
115 arbitrary = Paint <$> arbitrary
127 arbitrary = Paint <$> arbitrary
@@ -121,7 +133,9 @@ instance Arbitrary Paint where
121data MyRoseTree = MyRoseTree
133data MyRoseTree = MyRoseTree
122 { root :: String
134 { root :: String
123 , trees :: [MyRoseTree]
135 , trees :: [MyRoseTree]
124− } deriving (Show, Generic, ToJSON)
136+ } deriving (Show, Generic)
138+instance ToJSON MyRoseTree
126instance ToSchema MyRoseTree where
140instance ToSchema MyRoseTree where
127 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
141 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
@@ -138,7 +152,9 @@ instance Arbitrary MyRoseTree where
138-- Light (sum type)
152-- Light (sum type)
139-- ========================================================================
153-- ========================================================================
141−data Light = NoLight | LightFreq Double | LightColor Color deriving (Show, Generic, ToSchema)
155+data Light = NoLight | LightFreq Double | LightColor Color deriving (Show, Generic)
157+instance ToSchema Light
143instance ToJSON Light where
159instance ToJSON Light where
144 toJSON = genericToJSON defaultOptions { sumEncoding = ObjectWithSingleField }
160 toJSON = genericToJSON defaultOptions { sumEncoding = ObjectWithSingleField }