git.iko.soy/typeable/swagger2
on master help sign in
Add tests for bounded enum
commitce9375cf0225e34c34e7284b7989ec16814f08fb authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateTue 24 Nov 2015, 15:27 (11 years ago) parentc4b8cff
1 file changed+26−2
test/Data/Swagger/SchemaSpec.hs+26−2
test/Data/Swagger/SchemaSpec.hs+26−2
@@ -31,6 +31,8 @@ spec = do
3131 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
3232 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
3333 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
3436 context "Unary records" $ do
3537 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
3638 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
@@ -115,7 +117,7 @@ pointSchemaJSON = [aesonQQ|
115117
116118
117119-- ========================================================================
118−-- Point (record data type with custom fieldLabelModifier)
120+-- Color (bounded enum)
119121-- ========================================================================
120122data Color
121123 = Red
@@ -124,7 +126,7 @@ data Color
124126 deriving (Generic, Enum, Bounded, ToJSON)
125127
126128instance ToSchema Color where
127− toNamedSchema = genericToNamedSchemaBoundedEnum
129+ toNamedSchema = genericToNamedSchemaBoundedEnum defaultSchemaOptions
128130
129131colorSchemaJSON :: Value
130132colorSchemaJSON = [aesonQQ|
@@ -134,6 +136,28 @@ colorSchemaJSON = [aesonQQ|
134136}
135137|]
136138
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+
137161-- ========================================================================
138162-- Email (newtype with unwrapUnaryRecords set to True)
139163-- ========================================================================