models: include model's `description`

This commit is contained in:
Miroslav Bajtoš 2014-10-15 14:07:23 +02:00
parent dc815a8421
commit 060354cff8
2 changed files with 18 additions and 8 deletions

View File

@ -90,6 +90,7 @@ var modelHelper = module.exports = {
out[name] = {
id: name,
description: typeConverter.convertText(def.description),
properties: properties,
required: required
};

View File

@ -1,7 +1,7 @@
'use strict';
var modelHelper = require('../lib/model-helper');
var _assign = require('lodash.assign');
var _defaults = require('lodash.defaults');
var loopback = require('loopback');
var expect = require('chai').expect;
@ -139,6 +139,11 @@ describe('model-helper', function() {
var nameProp = def.properties.name;
expect(nameProp).to.have.property('description', 'a-description');
});
it('converts model field `description`', function() {
var def = buildSwaggerModels({}, { description: 'a-description' });
expect(def).to.have.property('description', 'a-description');
});
});
describe('related models', function() {
@ -212,23 +217,27 @@ describe('model-helper', function() {
});
// Simulates the format of a remoting class.
function buildSwaggerModels(model) {
var aClass = createModelCtor(model);
function buildSwaggerModels(modelProperties, modelOptions) {
var aClass = createModelCtor(modelProperties, modelOptions);
return modelHelper.generateModelDefinition(aClass.ctor, {}).testModel;
}
function createModelCtor(properties) {
function createModelCtor(properties, modelOptions) {
Object.keys(properties).forEach(function(name) {
var type = properties[name];
if (typeof type !== 'object' || Array.isArray(type))
properties[name] = { type: type };
});
var definition = {
name: 'testModel',
properties: properties
};
_defaults(definition, modelOptions);
var aClass = {
ctor: {
definition: {
name: 'testModel',
properties: properties
}
definition: definition
}
};
return aClass;