@@ -85,12 +85,14 @@ spec = do
85 prop "Paint" $ shouldValidate (Proxy :: Proxy Paint)
85 prop "Paint" $ shouldValidate (Proxy :: Proxy Paint)
86 prop "MyRoseTree" $ shouldValidate (Proxy :: Proxy MyRoseTree)
86 prop "MyRoseTree" $ shouldValidate (Proxy :: Proxy MyRoseTree)
87 prop "Light" $ shouldValidate (Proxy :: Proxy Light)
87 prop "Light" $ shouldValidate (Proxy :: Proxy Light)
88+ prop "ButtonImages" $ shouldValidate (Proxy :: Proxy ButtonImages)
89 describe "invalid cases" $ do
90 describe "invalid cases" $ do
90− prop "invalidPersonToJSON" $ shouldNotValidate invalidPersonToJSON
91+ prop "invalidPersonToJSON" $ shouldNotValidate invalidPersonToJSON
91− prop "invalidColorToJSON" $ shouldNotValidate invalidColorToJSON
92+ prop "invalidColorToJSON" $ shouldNotValidate invalidColorToJSON
92− prop "invalidPaintToJSON" $ shouldNotValidate invalidPaintToJSON
93+ prop "invalidPaintToJSON" $ shouldNotValidate invalidPaintToJSON
93− prop "invalidLightToJSON" $ shouldNotValidate invalidLightToJSON
94+ prop "invalidLightToJSON" $ shouldNotValidate invalidLightToJSON
95+ prop "invalidButtonImagesToJSON" $ shouldNotValidate invalidButtonImagesToJSON
95main :: IO ()
97main :: IO ()
96main = hspec spec
98main = hspec spec
@@ -193,6 +195,38 @@ instance Arbitrary Light where
193invalidLightToJSON :: Light -> Value
195invalidLightToJSON :: Light -> Value
194invalidLightToJSON = genericToJSON defaultOptions
196invalidLightToJSON = genericToJSON defaultOptions
198+-- ========================================================================
199+-- ButtonImages (bounded enum key mapping)
200+-- ========================================================================
202+data ButtonState = Neutral | Focus | Active | Hover | Disabled
203+ deriving (Show, Eq, Ord, Bounded, Enum, Generic)
205+instance ToJSON ButtonState
206+instance ToSchema ButtonState
207+instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
209+instance Arbitrary ButtonState where
210+ arbitrary = arbitraryBoundedEnum
212+type ImageUrl = T.Text
214+newtype ButtonImages = ButtonImages { getButtonImages :: Map ButtonState ImageUrl }
215+ deriving (Show, Generic)
217+instance ToJSON ButtonImages where
218+ toJSON = toJSON . getButtonImages
220+instance ToSchema ButtonImages where
221+ declareNamedSchema = genericDeclareNamedSchemaNewtype defaultSchemaOptions
222+ declareSchemaBoundedEnumKeyMapping
224+invalidButtonImagesToJSON :: ButtonImages -> Value
225+invalidButtonImagesToJSON = genericToJSON defaultOptions
227+instance Arbitrary ButtonImages where
228+ arbitrary = ButtonImages <$> arbitrary
196-- Arbitrary instances for common types
230-- Arbitrary instances for common types
198instance (Eq k, Hashable k, Arbitrary k, Arbitrary v) => Arbitrary (HashMap k v) where
232instance (Eq k, Hashable k, Arbitrary k, Arbitrary v) => Arbitrary (HashMap k v) where