git.iko.soy/typeable/swagger2
on master help sign in
Add tests for bounded enum
ce9375cNickolay Kudasov
test/Data/Swagger/SchemaSpec.hs+26−2
@@ -31,6 +31,8 @@ spec = do
31 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
31 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
32 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
32 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
33 context "Point (fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
33 context "Point (fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
34+ context "Color (bounded enum)" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
35+ context "Paint (record with bounded enum field)" $ checkToSchema (Proxy :: Proxy Paint) paintSchemaJSON
34 context "Unary records" $ do
36 context "Unary records" $ do
35 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
37 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
36 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
38 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
@@ -115,7 +117,7 @@ pointSchemaJSON = [aesonQQ|
115
117
116
118
117-- ========================================================================
119-- ========================================================================
118−-- Point (record data type with custom fieldLabelModifier)
120+-- Color (bounded enum)
119-- ========================================================================
121-- ========================================================================
120data Color
122data Color
121 = Red
123 = Red
@@ -124,7 +126,7 @@ data Color
124 deriving (Generic, Enum, Bounded, ToJSON)
126 deriving (Generic, Enum, Bounded, ToJSON)
125
127
126instance ToSchema Color where
128instance ToSchema Color where
127− toNamedSchema = genericToNamedSchemaBoundedEnum
129+ toNamedSchema = genericToNamedSchemaBoundedEnum defaultSchemaOptions
128
130
129colorSchemaJSON :: Value
131colorSchemaJSON :: Value
130colorSchemaJSON = [aesonQQ|
132colorSchemaJSON = [aesonQQ|
@@ -134,6 +136,28 @@ colorSchemaJSON = [aesonQQ|
134}
136}
135|]
137|]
136
138
139+-- ========================================================================
140+-- Paint (record with bounded enum property)
141+-- ========================================================================
142+
143+newtype Paint = Paint { color :: Color }
144+ deriving (Generic, ToSchema)
145+
146+paintSchemaJSON :: Value
147+paintSchemaJSON = [aesonQQ|
148+{
149+ "type": "object",
150+ "properties":
151+ {
152+ "color":
153+ {
154+ "$ref": "#/definitions/Color"
155+ }
156+ },
157+ "required": ["color"]
158+}
159+|]
160+
137-- ========================================================================
161-- ========================================================================
138-- Email (newtype with unwrapUnaryRecords set to True)
162-- Email (newtype with unwrapUnaryRecords set to True)
139-- ========================================================================
163-- ========================================================================