Skip to content

Commit

Permalink
use deflat from node-restify-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
z0mt3c committed Aug 16, 2013
1 parent ccab39d commit 4a87786
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
29 changes: 3 additions & 26 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,9 @@ var swagger = module.exports.swagger = require('swagger-doc');
var assert = require('assert');
var lingo = require('lingo');
var path = require('path');
var restifyValidation = require('node-restify-validation');
var validationUtils = restifyValidation.utils;

// TODO: will be part for the node-restify-validation
var deflat = module.exports.deflat = function (obj) {
var into = {};

_.each(obj, function (val, key) {
var splitted = key.split('.');

var cursor = into;

_.each(splitted, function (partialKey, i) {
if (i === (splitted.length - 1)) {
// last one -> set value!
cursor[partialKey] = val;
} else {
if (!_.has(cursor, partialKey)) {
cursor = cursor[partialKey] = {};
} else {
cursor = cursor[partialKey];
}
}
});
});

return into;
};

var defaultOptions = {
discoveryUrl: '/swagger/resources.json',
Expand Down Expand Up @@ -173,7 +150,7 @@ module.exports.loadRestifyRoutes = function () {
});

if (hasBodyParameters) {
model.properties = deflat(model.properties);
model.properties = validationUtils.deflat(model.properties);
extractSubtypes(model, swaggerDoc);
swaggerDoc.models[modelName] = model;
parameters.push({
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"underscore.string": "2.3.3",
"swagger-doc": "0.2.0",
"lingo": "*",
"path": "*"
"path": "*",
"node-restify-validation": "0.0.x"
},
"devDependencies": {
"restify": "2.6.0",
Expand Down

0 comments on commit 4a87786

Please sign in to comment.