@@ -9,6 +9,7 @@ import Data.Aeson
99import Data.Aeson.QQ
1010import Data.Char
1111import Data.Proxy
12+import Data.Set (Set)
1213import GHC.Generics
1314
1415import Data.Swagger
@@ -33,6 +34,7 @@ spec = do
3334 context "Point (fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
3435 context "Color (bounded enum)" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
3536 context "Paint (record with bounded enum field)" $ checkToSchema (Proxy :: Proxy Paint) paintSchemaJSON
37+ context "UserGroup (set newtype)" $ checkToSchema (Proxy :: Proxy UserGroup) userGroupSchemaJSON
3638 context "Unary records" $ do
3739 context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
3840 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
@@ -181,7 +183,7 @@ emailSchemaJSON = [aesonQQ|
181183-- ========================================================================
182184
183185newtype UserId = UserId Integer
184− deriving (Generic, ToSchema)
186+ deriving (Eq, Ord, Generic, ToSchema)
185187
186188userIdSchemaJSON :: Value
187189userIdSchemaJSON = [aesonQQ|
@@ -190,6 +192,22 @@ userIdSchemaJSON = [aesonQQ|
190192}
191193|]
192194
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+
193211-- ========================================================================
194212-- Player (record newtype)
195213-- ========================================================================