Corrected merge issues

This commit is contained in:
Shelby Sanders 2014-10-07 15:27:49 -07:00
parent 8563dd0463
commit 7f4e8b3f87
3 changed files with 32 additions and 27 deletions

View File

@ -19,7 +19,7 @@ var modelHelper = module.exports = {
*/
generateModelDefinition: function generateModelDefinition(modelClass, definitions) {
var processType = function(app, modelName, referencedModels) {
if (modelName) {
if (app && modelName) {
if (modelName.indexOf('[') == 0) {
modelName = modelName.replace(/[\[\]]/g, '');
}
@ -41,7 +41,7 @@ var modelHelper = module.exports = {
}
var required = [];
// Don't modify original properties.
var properties = _cloneDeep(def.rawProperties);
var properties = _cloneDeep(def.rawProperties || def.properties);
var referencedModels = [];
// Add models from settings
@ -72,9 +72,9 @@ var modelHelper = module.exports = {
// Eke a type out of the constructors we were passed.
prop = modelHelper.LDLPropToSwaggerDataType(prop);
processType(modelClass.app, prop.type, out);
processType(modelClass.app, prop.type, referencedModels);
if (prop.items) {
processType(modelClass.app, prop.items.type, out);
processType(modelClass.app, prop.items.type, referencedModels);
}
// Required props sit in a per-model array.
@ -125,25 +125,27 @@ var modelHelper = module.exports = {
}
}
var remotes = modelClass.sharedClass.methods();
for (var remoteIdx in remotes) {
var remote = remotes[remoteIdx];
var accepts = remote.accepts;
if (accepts) {
for (var acceptIdx in accepts) {
processType(modelClass.app, accepts[acceptIdx].type, referencedModels);
if (modelClass.sharedClass) {
var remotes = modelClass.sharedClass.methods();
for (var remoteIdx in remotes) {
var remote = remotes[remoteIdx];
var accepts = remote.accepts;
if (accepts) {
for (var acceptIdx in accepts) {
processType(modelClass.app, accepts[acceptIdx].type, referencedModels);
}
}
}
var returns = remote.returns;
if (returns) {
for (var returnIdx in returns) {
processType(modelClass.app, returns[returnIdx].type, referencedModels);
var returns = remote.returns;
if (returns) {
for (var returnIdx in returns) {
processType(modelClass.app, returns[returnIdx].type, referencedModels);
}
}
}
var errors = remote.errors;
if (errors) {
for (var errorIdx in errors) {
processType(modelClass.app, errors[errorIdx].responseModel, referencedModels);
var errors = remote.errors;
if (errors) {
for (var errorIdx in errors) {
processType(modelClass.app, errors[errorIdx].responseModel, referencedModels);
}
}
}
}
@ -181,6 +183,11 @@ var modelHelper = module.exports = {
// Swagger spec.
// https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#431-primitives
LDLPropToSwaggerDataType: function LDLPropToSwaggerDataType(prop) {
if (typeof prop === 'string') {
prop = {
type: prop
}
}
var out = _cloneDeep(prop);
out.type = modelHelper.getPropType(out.type);

View File

@ -147,7 +147,7 @@ var routeHelper = module.exports = {
case 'Boolean':
return 'boolean';
case 'buffer':
return 'byte';
return 'string';
case 'Date':
return 'date';
case 'number':

View File

@ -13,7 +13,7 @@ describe('route-helper', function() {
{ arg: 'avg', type: 'number' }
]
});
expect(doc.operations[0].type).to.equal('object');
expect(doc.operations[0].responseMessages[0].responseModel).to.equal('object');
});
it('converts path params when they exist in the route name', function() {
@ -60,8 +60,7 @@ describe('route-helper', function() {
]
});
var opDoc = doc.operations[0];
expect(opDoc.type).to.equal('array');
expect(opDoc.items).to.eql({type: 'customType'});
expect(opDoc.responseMessages[0].responseModel).to.equal('[customType]');
});
it('correctly converts return types (format)', function() {
@ -71,8 +70,7 @@ describe('route-helper', function() {
]
});
var opDoc = doc.operations[0];
expect(opDoc.type).to.equal('string');
expect(opDoc.format).to.equal('byte');
expect(opDoc.responseMessages[0].responseModel).to.equal('string');
});
});