Merge pull request #17 from strongloop/feature/fix-explorer-in-workspace
model-helper: handle array types with no item type
This commit is contained in:
commit
42c09ce470
|
@ -79,12 +79,14 @@ var modelHelper = module.exports = {
|
||||||
out.type = modelHelper.getPropType(out.type);
|
out.type = modelHelper.getPropType(out.type);
|
||||||
|
|
||||||
if (out.type === 'array') {
|
if (out.type === 'array') {
|
||||||
var arrayProp = prop.type[0];
|
var hasItemType = typeof prop.type !== 'string' && prop.type.length;
|
||||||
if (!arrayProp.type) arrayProp = {type: arrayProp};
|
|
||||||
out.items = modelHelper.LDLPropToSwaggerDataType(arrayProp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (out.type === 'date') {
|
if (hasItemType) {
|
||||||
|
var arrayProp = prop.type[0];
|
||||||
|
if (!arrayProp.type) arrayProp = {type: arrayProp};
|
||||||
|
out.items = modelHelper.LDLPropToSwaggerDataType(arrayProp);
|
||||||
|
}
|
||||||
|
} else if (out.type === 'date') {
|
||||||
out.type = 'string';
|
out.type = 'string';
|
||||||
out.format = 'date';
|
out.format = 'date';
|
||||||
} else if (out.type === 'buffer') {
|
} else if (out.type === 'buffer') {
|
||||||
|
|
|
@ -80,6 +80,22 @@ describe('model-helper', function() {
|
||||||
type: 'string', format: 'date'
|
type: 'string', format: 'date'
|
||||||
}});
|
}});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('converts [] type', function() {
|
||||||
|
var def = getDefinition({
|
||||||
|
array: []
|
||||||
|
});
|
||||||
|
var prop = def.properties.array;
|
||||||
|
expect(prop).to.eql({ type: 'array' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts "array" type', function() {
|
||||||
|
var def = getDefinition({
|
||||||
|
array: 'array'
|
||||||
|
});
|
||||||
|
var prop = def.properties.array;
|
||||||
|
expect(prop).to.eql({ type: 'array' });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue