git.iko.soy/typeable/swagger2
on master help sign in
Add unary data type tests
commit9b237b9f1a73df9ab6972ce46d426853125f0644 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateTue 24 Nov 2015, 00:14 (11 years ago) parent443a0ed
1 file changed+65−1
test/Data/Swagger/SchemaSpec.hs+65−1
test/Data/Swagger/SchemaSpec.hs+65−1
@@ -24,7 +24,11 @@ spec = do
2424 describe "Generic ToSchema" $ do
2525 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
2626 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
2832 describe "toSchemaBoundedEnum" $ do
2933 context "Color" $ checkToSchema (Proxy :: Proxy Color) colorSchemaJSON
3034
@@ -118,3 +122,63 @@ colorSchemaJSON = [aesonQQ|
118122}
119123|]
120124
125+-- ========================================================================
126+-- Email (newtype with unwrapUnaryRecords set to True)
127+-- ========================================================================
128+
129+newtype Email = Email { getEmail :: String }
130+ deriving (Generic)
131+
132+instance ToSchema Email where
133+ toSchema = genericToSchema defaultSchemaOptions
134+ { unwrapUnaryRecords = True }
135+
136+emailSchemaJSON :: Value
137+emailSchemaJSON = [aesonQQ|
138+{
139+ "type": "string"
140+}
141+|]
142+
143+-- ========================================================================
144+-- UserId (non-record newtype)
145+-- ========================================================================
146+
147+newtype UserId = UserId Integer
148+ deriving (Generic, ToSchema)
149+
150+userIdSchemaJSON :: Value
151+userIdSchemaJSON = [aesonQQ|
152+{
153+ "type": "integer"
154+}
155+|]
156+
157+-- ========================================================================
158+-- Player (record newtype)
159+-- ========================================================================
160+
161+newtype Player = Player
162+ { position :: Point
163+ } deriving (Generic, ToSchema)
164+
165+playerSchemaJSON :: Value
166+playerSchemaJSON = [aesonQQ|
167+{
168+ "type": "object",
169+ "properties":
170+ {
171+ "position":
172+ {
173+ "type": "object",
174+ "properties":
175+ {
176+ "x": { "type": "number" },
177+ "y": { "type": "number" }
178+ },
179+ "required": [ "x", "y" ]
180+ }
181+ },
182+ "required": ["position"]
183+}
184+|]