@@ -25,10 +25,15 @@ spec = do
2525 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
2626 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
2727 context "Point (custom fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
28+ describe "toSchemaBoundedEnum" $ do
29+ context "Color" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
2830
2931main :: IO ()
3032main = hspec spec
3133
34+-- ========================================================================
35+-- Person (simple record with optional fields)
36+-- ========================================================================
3237data Person = Person
3338 { name :: String
3439 , phone :: Integer
@@ -49,6 +54,9 @@ personSchemaJSON = [aesonQQ|
4954}
5055|]
5156
57+-- ========================================================================
58+-- ISPair (non-record product data type)
59+-- ========================================================================
5260data ISPair = ISPair Integer String
5361 deriving (Generic, ToSchema)
5462
@@ -64,6 +72,9 @@ ispairSchemaJSON = [aesonQQ|
6472}
6573|]
6674
75+-- ========================================================================
76+-- Point (record data type with custom fieldLabelModifier)
77+-- ========================================================================
6778data Point = Point
6879 { pointX :: Double
6980 , pointY :: Double
@@ -86,3 +97,24 @@ pointSchemaJSON = [aesonQQ|
8697}
8798|]
8899
100+
101+-- ========================================================================
102+-- Point (record data type with custom fieldLabelModifier)
103+-- ========================================================================
104+data Color
105+ = Red
106+ | Green
107+ | Blue
108+ deriving (Generic, Enum, Bounded, ToJSON)
109+
110+instance ToSchema Color where
111+ toSchema = toSchemaBoundedEnum
112+
113+colorSchemaJSON :: Value
114+colorSchemaJSON = [aesonQQ|
115+{
116+ "type": "string",
117+ "enum": ["Red", "Green", "Blue"]
118+}
119+|]
120+