@@ -24,7 +24,11 @@ spec = do
24 describe "Generic ToSchema" $ do
24 describe "Generic ToSchema" $ 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 (fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
28+ context "Unary records" $ do
29+ context "Email (unwrapUnaryRecords)" $ checkToSchema (Proxy :: Proxy Email) emailSchemaJSON
30+ context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
31+ context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
28 describe "toSchemaBoundedEnum" $ do
32 describe "toSchemaBoundedEnum" $ do
29 context "Color" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
33 context "Color" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
@@ -118,3 +122,63 @@ colorSchemaJSON = [aesonQQ|
125+-- ========================================================================
126+-- Email (newtype with unwrapUnaryRecords set to True)
127+-- ========================================================================
129+newtype Email = Email { getEmail :: String }
132+instance ToSchema Email where
133+ toSchema = genericToSchema defaultSchemaOptions
134+ { unwrapUnaryRecords = True }
136+emailSchemaJSON :: Value
137+emailSchemaJSON = [aesonQQ|
143+-- ========================================================================
144+-- UserId (non-record newtype)
145+-- ========================================================================
147+newtype UserId = UserId Integer
148+ deriving (Generic, ToSchema)
150+userIdSchemaJSON :: Value
151+userIdSchemaJSON = [aesonQQ|
157+-- ========================================================================
158+-- Player (record newtype)
159+-- ========================================================================
161+newtype Player = Player
163+ } deriving (Generic, ToSchema)
165+playerSchemaJSON :: Value
166+playerSchemaJSON = [aesonQQ|
176+ "x": { "type": "number" },
177+ "y": { "type": "number" }
179+ "required": [ "x", "y" ]
182+ "required": ["position"]