@@ -116,7 +116,7 @@ test('handling additional properties with one of patternProperty types', functio
116
116
assert . deepEqual ( result , expected , 'additionalProperties set to false' ) ;
117
117
} ) ;
118
118
119
- test ( 'keeping additionalProperties with object type ' , function ( assert ) {
119
+ test ( 'handling additionalProperties with matching objects ' , function ( assert ) {
120
120
var schema
121
121
, result
122
122
, expected
@@ -127,14 +127,81 @@ test('keeping additionalProperties with object type', function(assert) {
127
127
schema = {
128
128
type : 'object' ,
129
129
additionalProperties : {
130
- type : 'object'
130
+ type : 'object' ,
131
+ properties : {
132
+ test : {
133
+ type : 'string'
134
+ }
135
+ }
131
136
} ,
132
137
'x-patternProperties' : {
133
138
'^[a-z]*$' : {
134
139
type : 'string'
135
140
} ,
136
141
'^[A-Z]*$' : {
137
- type : 'object'
142
+ type : 'object' ,
143
+ properties : {
144
+ test : {
145
+ type : 'string'
146
+ }
147
+ }
148
+ }
149
+ }
150
+ } ;
151
+
152
+ result = convert ( schema , { supportPatternProperties : true } ) ;
153
+
154
+ expected = {
155
+ $schema : 'http://json-schema.org/draft-04/schema#' ,
156
+ type : 'object' ,
157
+ additionalProperties : false ,
158
+ patternProperties : {
159
+ '^[a-z]*$' : {
160
+ type : 'string'
161
+ } ,
162
+ '^[A-Z]*$' : {
163
+ type : 'object' ,
164
+ properties : {
165
+ test : {
166
+ type : 'string'
167
+ }
168
+ }
169
+ }
170
+ }
171
+ } ;
172
+
173
+ assert . deepEqual ( result , expected , 'additionalProperties set to false' ) ;
174
+ } ) ;
175
+
176
+ test ( 'handling additionalProperties with non-matching objects' , function ( assert ) {
177
+ var schema
178
+ , result
179
+ , expected
180
+ ;
181
+
182
+ assert . plan ( 1 ) ;
183
+
184
+ schema = {
185
+ type : 'object' ,
186
+ additionalProperties : {
187
+ type : 'object' ,
188
+ properties : {
189
+ test : {
190
+ type : 'string'
191
+ }
192
+ }
193
+ } ,
194
+ 'x-patternProperties' : {
195
+ '^[a-z]*$' : {
196
+ type : 'string'
197
+ } ,
198
+ '^[A-Z]*$' : {
199
+ type : 'object' ,
200
+ properties : {
201
+ test : {
202
+ type : 'integer'
203
+ }
204
+ }
138
205
}
139
206
}
140
207
} ;
@@ -145,22 +212,32 @@ test('keeping additionalProperties with object type', function(assert) {
145
212
$schema : 'http://json-schema.org/draft-04/schema#' ,
146
213
type : 'object' ,
147
214
additionalProperties : {
148
- type : 'object'
215
+ type : 'object' ,
216
+ properties : {
217
+ test : {
218
+ type : 'string'
219
+ }
220
+ }
149
221
} ,
150
222
patternProperties : {
151
223
'^[a-z]*$' : {
152
224
type : 'string'
153
225
} ,
154
226
'^[A-Z]*$' : {
155
- type : 'object'
227
+ type : 'object' ,
228
+ properties : {
229
+ test : {
230
+ type : 'integer'
231
+ }
232
+ }
156
233
}
157
234
}
158
235
} ;
159
236
160
- assert . deepEqual ( result , expected , 'additionalProperties kept unchanged ' ) ;
237
+ assert . deepEqual ( result , expected , 'additionalProperties not changed ' ) ;
161
238
} ) ;
162
239
163
- test ( 'keeping additionalProperties with array type ' , function ( assert ) {
240
+ test ( 'handling additionalProperties with matching array ' , function ( assert ) {
164
241
var schema
165
242
, result
166
243
, expected
@@ -194,12 +271,7 @@ test('keeping additionalProperties with array type', function(assert) {
194
271
expected = {
195
272
$schema : 'http://json-schema.org/draft-04/schema#' ,
196
273
type : 'object' ,
197
- additionalProperties : {
198
- type : 'array' ,
199
- items : {
200
- type : 'string'
201
- }
202
- } ,
274
+ additionalProperties : false ,
203
275
patternProperties : {
204
276
'^[a-z]*$' : {
205
277
type : 'string'
@@ -213,7 +285,64 @@ test('keeping additionalProperties with array type', function(assert) {
213
285
}
214
286
} ;
215
287
216
- assert . deepEqual ( result , expected , 'additionalProperties kept unchanged' ) ;
288
+ assert . deepEqual ( result , expected , 'additionalProperties set to false' ) ;
289
+ } ) ;
290
+
291
+ test ( 'handling additionalProperties with composition types' , function ( assert ) {
292
+ var schema
293
+ , result
294
+ , expected
295
+ ;
296
+
297
+ assert . plan ( 1 ) ;
298
+
299
+ schema = {
300
+ type : 'object' ,
301
+ additionalProperties : {
302
+ oneOf : [
303
+ {
304
+ type : 'string'
305
+ } ,
306
+ {
307
+ type : 'integer'
308
+ }
309
+ ]
310
+ } ,
311
+ 'x-patternProperties' : {
312
+ '^[a-z]*$' : {
313
+ oneOf : [
314
+ {
315
+ type : 'string'
316
+ } ,
317
+ {
318
+ type : 'integer'
319
+ }
320
+ ]
321
+ }
322
+ }
323
+ } ;
324
+
325
+ result = convert ( schema , { supportPatternProperties : true } ) ;
326
+
327
+ expected = {
328
+ $schema : 'http://json-schema.org/draft-04/schema#' ,
329
+ type : 'object' ,
330
+ additionalProperties : false ,
331
+ patternProperties : {
332
+ '^[a-z]*$' : {
333
+ oneOf : [
334
+ {
335
+ type : 'string'
336
+ } ,
337
+ {
338
+ type : 'integer'
339
+ }
340
+ ]
341
+ }
342
+ }
343
+ } ;
344
+
345
+ assert . deepEqual ( result , expected , 'additionalProperties set to false' ) ;
217
346
} ) ;
218
347
219
348
test ( 'not supporting patternProperties' , function ( assert ) {
@@ -369,3 +498,4 @@ test('additionalProperties not modified if set to true', function(assert) {
369
498
370
499
assert . deepEqual ( result , expected , 'additionalProperties not removed' ) ;
371
500
} ) ;
501
+
0 commit comments