git.iko.soy/typeable/openapi3
on master help sign in
Add test for Set schema
3f246d8Nickolay Kudasov
swagger2.cabal+1
@@ -52,6 +52,7 @@ test-suite spec
52 , text
52 , text
53 , aeson
53 , aeson
54 , aeson-qq
54 , aeson-qq
55+ , containers
55 , unordered-containers
56 , unordered-containers
56 , vector
57 , vector
57 other-modules:
58 other-modules:
test/Data/Swagger/SchemaSpec.hs+19−1
@@ -9,6 +9,7 @@ import Data.Aeson
9import Data.Aeson.QQ
9import Data.Aeson.QQ
10import Data.Char
10import Data.Char
11import Data.Proxy
11import Data.Proxy
12+import Data.Set (Set)
12import GHC.Generics
13import GHC.Generics
13
14
14import Data.Swagger
15import Data.Swagger
@@ -33,6 +34,7 @@ spec = do
33 context "Point (fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
34 context "Point (fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
34 context "Color (bounded enum)" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
35 context "Color (bounded enum)" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
35 context "Paint (record with bounded enum field)" $ checkToSchema (Proxy :: Proxy Paint) paintSchemaJSON
36 context "Paint (record with bounded enum field)" $ checkToSchema (Proxy :: Proxy Paint) paintSchemaJSON
37+ context "UserGroup (set newtype)" $ checkToSchema (Proxy :: Proxy UserGroup) userGroupSchemaJSON
36 context "Unary records" $ do
38 context "Unary records" $ do
37 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
39 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
38 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
40 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
@@ -181,7 +183,7 @@ emailSchemaJSON = [aesonQQ|
181-- ========================================================================
183-- ========================================================================
182
184
183newtype UserId = UserId Integer
185newtype UserId = UserId Integer
184− deriving (Generic, ToSchema)
186+ deriving (Eq, Ord, Generic, ToSchema)
185
187
186userIdSchemaJSON :: Value
188userIdSchemaJSON :: Value
187userIdSchemaJSON = [aesonQQ|
189userIdSchemaJSON = [aesonQQ|
@@ -190,6 +192,22 @@ userIdSchemaJSON = [aesonQQ|
190}
192}
191|]
193|]
192
194
195+-- ========================================================================
196+-- UserGroup (set newtype)
197+-- ========================================================================
198+
199+newtype UserGroup = UserGroup (Set UserId)
200+ deriving (Generic, ToSchema)
201+
202+userGroupSchemaJSON :: Value
203+userGroupSchemaJSON = [aesonQQ|
204+{
205+ "type": "array",
206+ "items": { "$ref": "#/definitions/UserId" },
207+ "uniqueItems": true
208+}
209+|]
210+
193-- ========================================================================
211-- ========================================================================
194-- Player (record newtype)
212-- Player (record newtype)
195-- ========================================================================
213-- ========================================================================