@@ -25,10 +25,15 @@ spec = do
25 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
25 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
26 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
26 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
27 context "Point (custom fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
27 context "Point (custom fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
28+ describe "toSchemaBoundedEnum" $ do
29+ context "Color" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
29main :: IO ()
31main :: IO ()
30main = hspec spec
32main = hspec spec
34+-- ========================================================================
35+-- Person (simple record with optional fields)
36+-- ========================================================================
32data Person = Person
37data Person = Person
33 { name :: String
38 { name :: String
34 , phone :: Integer
39 , phone :: Integer
@@ -49,6 +54,9 @@ personSchemaJSON = [aesonQQ|
57+-- ========================================================================
58+-- ISPair (non-record product data type)
59+-- ========================================================================
52data ISPair = ISPair Integer String
60data ISPair = ISPair Integer String
53 deriving (Generic, ToSchema)
61 deriving (Generic, ToSchema)
@@ -64,6 +72,9 @@ ispairSchemaJSON = [aesonQQ|
75+-- ========================================================================
76+-- Point (record data type with custom fieldLabelModifier)
77+-- ========================================================================
67data Point = Point
78data Point = Point
68 { pointX :: Double
79 { pointX :: Double
69 , pointY :: Double
80 , pointY :: Double
@@ -86,3 +97,24 @@ pointSchemaJSON = [aesonQQ|
101+-- ========================================================================
102+-- Point (record data type with custom fieldLabelModifier)
103+-- ========================================================================
108+ deriving (Generic, Enum, Bounded, ToJSON)
110+instance ToSchema Color where
111+ toSchema = toSchemaBoundedEnum
113+colorSchemaJSON :: Value
114+colorSchemaJSON = [aesonQQ|
117+ "enum": ["Red", "Green", "Blue"]