git.iko.soy/typeable/openapi3
on master help sign in
Add test for toSchemaBoundedEnum
80fedd0Nickolay Kudasov
test/Data/Swagger/SchemaSpec.hs+32
@@ -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
28
30
29main :: IO ()
31main :: IO ()
30main = hspec spec
32main = hspec spec
31
33
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|
49}
54}
50|]
55|]
51
56
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)
54
62
@@ -64,6 +72,9 @@ ispairSchemaJSON = [aesonQQ|
64}
72}
65|]
73|]
66
74
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|
86}
97}
87|]
98|]
88
99
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+