@@ -85,12 +85,14 @@ spec = do
8585 prop "Paint" $ shouldValidate (Proxy :: Proxy Paint)
8686 prop "MyRoseTree" $ shouldValidate (Proxy :: Proxy MyRoseTree)
8787 prop "Light" $ shouldValidate (Proxy :: Proxy Light)
88+ prop "ButtonImages" $ shouldValidate (Proxy :: Proxy ButtonImages)
8889
8990 describe "invalid cases" $ do
90− prop "invalidPersonToJSON" $ shouldNotValidate invalidPersonToJSON
91− prop "invalidColorToJSON" $ shouldNotValidate invalidColorToJSON
92− prop "invalidPaintToJSON" $ shouldNotValidate invalidPaintToJSON
93− prop "invalidLightToJSON" $ shouldNotValidate invalidLightToJSON
91+ prop "invalidPersonToJSON" $ shouldNotValidate invalidPersonToJSON
92+ prop "invalidColorToJSON" $ shouldNotValidate invalidColorToJSON
93+ prop "invalidPaintToJSON" $ shouldNotValidate invalidPaintToJSON
94+ prop "invalidLightToJSON" $ shouldNotValidate invalidLightToJSON
95+ prop "invalidButtonImagesToJSON" $ shouldNotValidate invalidButtonImagesToJSON
9496
9597main :: IO ()
9698main = hspec spec
@@ -193,6 +195,38 @@ instance Arbitrary Light where
193195invalidLightToJSON :: Light -> Value
194196invalidLightToJSON = genericToJSON defaultOptions
195197
198+-- ========================================================================
199+-- ButtonImages (bounded enum key mapping)
200+-- ========================================================================
201+
202+data ButtonState = Neutral | Focus | Active | Hover | Disabled
203+ deriving (Show, Eq, Ord, Bounded, Enum, Generic)
204+
205+instance ToJSON ButtonState
206+instance ToSchema ButtonState
207+instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
208+
209+instance Arbitrary ButtonState where
210+ arbitrary = arbitraryBoundedEnum
211+
212+type ImageUrl = T.Text
213+
214+newtype ButtonImages = ButtonImages { getButtonImages :: Map ButtonState ImageUrl }
215+ deriving (Show, Generic)
216+
217+instance ToJSON ButtonImages where
218+ toJSON = toJSON . getButtonImages
219+
220+instance ToSchema ButtonImages where
221+ declareNamedSchema = genericDeclareNamedSchemaNewtype defaultSchemaOptions
222+ declareSchemaBoundedEnumKeyMapping
223+
224+invalidButtonImagesToJSON :: ButtonImages -> Value
225+invalidButtonImagesToJSON = genericToJSON defaultOptions
226+
227+instance Arbitrary ButtonImages where
228+ arbitrary = ButtonImages <$> arbitrary
229+
196230-- Arbitrary instances for common types
197231
198232instance (Eq k, Hashable k, Arbitrary k, Arbitrary v) => Arbitrary (HashMap k v) where