add $ref and remove type for models

This commit is contained in:
Ying Tang 2015-03-26 22:23:24 -07:00
parent fa0c8d160a
commit 27e5895aa5
2 changed files with 7 additions and 1 deletions

View File

@ -5,6 +5,7 @@
*/
var _cloneDeep = require('lodash.clonedeep');
var translateDataTypeKeys = require('./translate-data-type-keys');
var TYPES_PRIMITIVE = ['array', 'boolean', 'integer', 'number', 'null', 'object', 'string'];
/**
* Export the modelHelper singleton.
@ -83,6 +84,11 @@ var modelHelper = module.exports = {
// Change mismatched keys.
prop = translateDataTypeKeys(prop);
if (TYPES_PRIMITIVE.indexOf(prop.type) === -1 ){
prop.$ref = prop.type;
delete prop.type;
}
// Assign this back to the properties object.
properties[key] = prop;

View File

@ -118,7 +118,7 @@ describe('model-helper', function() {
address: Address
});
var prop = def.properties.address;
expect(prop).to.eql({ type: 'Address' });
expect(prop).to.eql({ $ref: 'Address' });
});
});