From 060354cff8e80b81ac7f22c936523a774332b974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 15 Oct 2014 14:07:23 +0200 Subject: [PATCH] models: include model's `description` --- lib/model-helper.js | 1 + test/model-helper.test.js | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/model-helper.js b/lib/model-helper.js index 508df88..51fbf53 100644 --- a/lib/model-helper.js +++ b/lib/model-helper.js @@ -90,6 +90,7 @@ var modelHelper = module.exports = { out[name] = { id: name, + description: typeConverter.convertText(def.description), properties: properties, required: required }; diff --git a/test/model-helper.test.js b/test/model-helper.test.js index 299f5ae..b183400 100644 --- a/test/model-helper.test.js +++ b/test/model-helper.test.js @@ -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;