model-helper: handle arrays with undefined items

This commit is contained in:
Miroslav Bajtoš 2014-07-22 21:52:25 +02:00
parent 511d955e2e
commit 536fa4c577
2 changed files with 11 additions and 1 deletions

View File

@ -79,7 +79,7 @@ var modelHelper = module.exports = {
out.type = modelHelper.getPropType(out.type);
if (out.type === 'array') {
var hasItemType = typeof prop.type !== 'string' && prop.type.length;
var hasItemType = typeof prop.type !== 'string' && prop.type[0];
if (hasItemType) {
var arrayProp = prop.type[0];

View File

@ -89,6 +89,16 @@ describe('model-helper', function() {
expect(prop).to.eql({ type: 'array' });
});
it('converts [undefined] type', function() {
var def = getDefinition({
// This value is somehow provided by loopback-boot called from
// loopback-workspace.
array: [undefined]
});
var prop = def.properties.array;
expect(prop).to.eql({ type: 'array' });
});
it('converts "array" type', function() {
var def = getDefinition({
array: 'array'