Corrected merge issues
This commit is contained in:
parent
8563dd0463
commit
7f4e8b3f87
|
@ -19,7 +19,7 @@ var modelHelper = module.exports = {
|
||||||
*/
|
*/
|
||||||
generateModelDefinition: function generateModelDefinition(modelClass, definitions) {
|
generateModelDefinition: function generateModelDefinition(modelClass, definitions) {
|
||||||
var processType = function(app, modelName, referencedModels) {
|
var processType = function(app, modelName, referencedModels) {
|
||||||
if (modelName) {
|
if (app && modelName) {
|
||||||
if (modelName.indexOf('[') == 0) {
|
if (modelName.indexOf('[') == 0) {
|
||||||
modelName = modelName.replace(/[\[\]]/g, '');
|
modelName = modelName.replace(/[\[\]]/g, '');
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ var modelHelper = module.exports = {
|
||||||
}
|
}
|
||||||
var required = [];
|
var required = [];
|
||||||
// Don't modify original properties.
|
// Don't modify original properties.
|
||||||
var properties = _cloneDeep(def.rawProperties);
|
var properties = _cloneDeep(def.rawProperties || def.properties);
|
||||||
|
|
||||||
var referencedModels = [];
|
var referencedModels = [];
|
||||||
// Add models from settings
|
// Add models from settings
|
||||||
|
@ -72,9 +72,9 @@ var modelHelper = module.exports = {
|
||||||
|
|
||||||
// Eke a type out of the constructors we were passed.
|
// Eke a type out of the constructors we were passed.
|
||||||
prop = modelHelper.LDLPropToSwaggerDataType(prop);
|
prop = modelHelper.LDLPropToSwaggerDataType(prop);
|
||||||
processType(modelClass.app, prop.type, out);
|
processType(modelClass.app, prop.type, referencedModels);
|
||||||
if (prop.items) {
|
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.
|
// Required props sit in a per-model array.
|
||||||
|
@ -125,25 +125,27 @@ var modelHelper = module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var remotes = modelClass.sharedClass.methods();
|
if (modelClass.sharedClass) {
|
||||||
for (var remoteIdx in remotes) {
|
var remotes = modelClass.sharedClass.methods();
|
||||||
var remote = remotes[remoteIdx];
|
for (var remoteIdx in remotes) {
|
||||||
var accepts = remote.accepts;
|
var remote = remotes[remoteIdx];
|
||||||
if (accepts) {
|
var accepts = remote.accepts;
|
||||||
for (var acceptIdx in accepts) {
|
if (accepts) {
|
||||||
processType(modelClass.app, accepts[acceptIdx].type, referencedModels);
|
for (var acceptIdx in accepts) {
|
||||||
|
processType(modelClass.app, accepts[acceptIdx].type, referencedModels);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
var returns = remote.returns;
|
||||||
var returns = remote.returns;
|
if (returns) {
|
||||||
if (returns) {
|
for (var returnIdx in returns) {
|
||||||
for (var returnIdx in returns) {
|
processType(modelClass.app, returns[returnIdx].type, referencedModels);
|
||||||
processType(modelClass.app, returns[returnIdx].type, referencedModels);
|
}
|
||||||
}
|
}
|
||||||
}
|
var errors = remote.errors;
|
||||||
var errors = remote.errors;
|
if (errors) {
|
||||||
if (errors) {
|
for (var errorIdx in errors) {
|
||||||
for (var errorIdx in errors) {
|
processType(modelClass.app, errors[errorIdx].responseModel, referencedModels);
|
||||||
processType(modelClass.app, errors[errorIdx].responseModel, referencedModels);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,6 +183,11 @@ var modelHelper = module.exports = {
|
||||||
// Swagger spec.
|
// Swagger spec.
|
||||||
// https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#431-primitives
|
// https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#431-primitives
|
||||||
LDLPropToSwaggerDataType: function LDLPropToSwaggerDataType(prop) {
|
LDLPropToSwaggerDataType: function LDLPropToSwaggerDataType(prop) {
|
||||||
|
if (typeof prop === 'string') {
|
||||||
|
prop = {
|
||||||
|
type: prop
|
||||||
|
}
|
||||||
|
}
|
||||||
var out = _cloneDeep(prop);
|
var out = _cloneDeep(prop);
|
||||||
out.type = modelHelper.getPropType(out.type);
|
out.type = modelHelper.getPropType(out.type);
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ var routeHelper = module.exports = {
|
||||||
case 'Boolean':
|
case 'Boolean':
|
||||||
return 'boolean';
|
return 'boolean';
|
||||||
case 'buffer':
|
case 'buffer':
|
||||||
return 'byte';
|
return 'string';
|
||||||
case 'Date':
|
case 'Date':
|
||||||
return 'date';
|
return 'date';
|
||||||
case 'number':
|
case 'number':
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe('route-helper', function() {
|
||||||
{ arg: 'avg', type: 'number' }
|
{ 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() {
|
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];
|
var opDoc = doc.operations[0];
|
||||||
expect(opDoc.type).to.equal('array');
|
expect(opDoc.responseMessages[0].responseModel).to.equal('[customType]');
|
||||||
expect(opDoc.items).to.eql({type: 'customType'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('correctly converts return types (format)', function() {
|
it('correctly converts return types (format)', function() {
|
||||||
|
@ -71,8 +70,7 @@ describe('route-helper', function() {
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
var opDoc = doc.operations[0];
|
var opDoc = doc.operations[0];
|
||||||
expect(opDoc.type).to.equal('string');
|
expect(opDoc.responseMessages[0].responseModel).to.equal('string');
|
||||||
expect(opDoc.format).to.equal('byte');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue