Skip to content

Commit aa9210a

Browse files
author
Mika Kunnas
committed
additionalProperties of type array not removed
1 parent 2bdf0dc commit aa9210a

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function patternPropertiesHandler(schema) {
166166
for (pattern in patternsObj) {
167167
type = patternsObj[pattern].type;
168168

169-
if ((type === additProps.type) && type !== 'object') {
169+
if ((type === additProps.type) && type !== 'object' && type !== 'array') {
170170
schema.additionalProperties = false;
171171
break;
172172
}

test/pattern_properties.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,62 @@ test('keeping additionalProperties with object type', function(assert) {
160160
assert.deepEqual(result, expected, 'additionalProperties kept unchanged');
161161
});
162162

163+
test('keeping additionalProperties with array type', function(assert) {
164+
var schema
165+
, result
166+
, expected
167+
;
168+
169+
assert.plan(1);
170+
171+
schema = {
172+
type: 'object',
173+
additionalProperties: {
174+
type: 'array',
175+
items: {
176+
type: 'string'
177+
}
178+
},
179+
'x-patternProperties': {
180+
'^[a-z]*$': {
181+
type: 'string'
182+
},
183+
'^[A-Z]*$': {
184+
type: 'array',
185+
items: {
186+
type: 'string'
187+
}
188+
}
189+
}
190+
};
191+
192+
result = convert(schema, {supportPatternProperties: true});
193+
194+
expected = {
195+
$schema: 'http://json-schema.org/draft-04/schema#',
196+
type: 'object',
197+
additionalProperties: {
198+
type: 'array',
199+
items: {
200+
type: 'string'
201+
}
202+
},
203+
patternProperties: {
204+
'^[a-z]*$': {
205+
type: 'string'
206+
},
207+
'^[A-Z]*$': {
208+
type: 'array',
209+
items: {
210+
type: 'string'
211+
}
212+
}
213+
}
214+
};
215+
216+
assert.deepEqual(result, expected, 'additionalProperties kept unchanged');
217+
});
218+
163219
test('not supporting patternProperties', function(assert) {
164220
var schema
165221
, result
@@ -278,3 +334,38 @@ test('setting custom patternProperties handler', function(assert) {
278334

279335
assert.deepEqual(result, expected, 'handler with custom handler');
280336
});
337+
338+
test('additionalProperties not modified if set to true', function(assert) {
339+
var schema
340+
, result
341+
, expected
342+
, options
343+
;
344+
345+
assert.plan(1);
346+
347+
schema = {
348+
type: 'object',
349+
additionalProperties: true,
350+
'x-patternProperties': {
351+
'^[a-z]*$': {
352+
type: 'string'
353+
}
354+
}
355+
};
356+
357+
result = convert(schema, {supportPatternProperties: true});
358+
359+
expected = {
360+
$schema: 'http://json-schema.org/draft-04/schema#',
361+
type: 'object',
362+
additionalProperties: true,
363+
patternProperties: {
364+
'^[a-z]*$': {
365+
type: 'string'
366+
}
367+
}
368+
};
369+
370+
assert.deepEqual(result, expected, 'additionalProperties not removed');
371+
});

0 commit comments

Comments
 (0)