added a check to the js_api generator that will ensure that each url has a unique variable signature.

This commit is contained in:
Spencer Alger
2014-01-09 16:17:19 -07:00
parent 92991a0bda
commit f6de504c3f

View File

@ -151,6 +151,7 @@ module.exports = function (done) {
}
var urls = _.difference(def.url.paths, aliases[name]);
var urlSignatures = [];
urls = _.map(urls, function (url) {
var optionalVars = {};
var requiredVars = {};
@ -170,6 +171,8 @@ module.exports = function (done) {
target[name] = _.omit(param, 'required', 'description', 'name');
}
urlSignatures.push(_.union(_.keys(optionalVars), _.keys(requiredVars)).sort().join(':'));
return _.omit({
fmt: url.replace(urlParamRE, function (full, match) {
return '<%=' + _.camelCase(match) + '%>';
@ -182,6 +185,10 @@ module.exports = function (done) {
});
});
if (urlSignatures.length !== _.unique(urlSignatures).length) {
throw new Error('Multiple URLS with the same signature detected for ' + spec.name);
}
if (urls.length > 1) {
spec.urls = _.map(_.sortBy(urls, 'sortOrder'), function (url) {
return _.omit(url, 'sortOrder');