From 281fbf1fcbd32cf5fdc8df8aa0cddbd4ea337917 Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Tue, 14 Apr 2015 18:31:01 +0200 Subject: [PATCH] Saner manifest handling. Controllers and tests are coerced into an object/array on parse instead of on demand. Removed unnecessary function. --- .../modules/org/arangodb/foxx/manager.js | 23 +++++++++++++++---- .../modules/org/arangodb/foxx/routing.js | 4 +--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/js/server/modules/org/arangodb/foxx/manager.js b/js/server/modules/org/arangodb/foxx/manager.js index 28c9198ae4..28c8fb8bf1 100644 --- a/js/server/modules/org/arangodb/foxx/manager.js +++ b/js/server/modules/org/arangodb/foxx/manager.js @@ -144,16 +144,23 @@ var manifestSchema = { }) ), scripts: ( - joi.object() + joi.object().optional() .pattern(RE_EMPTY, joi.forbidden()) .pattern(RE_NOT_EMPTY, joi.string().required()) - .default(function () {return {};}, 'empty scripts object') + .default(Object, 'empty scripts object') ), setup: joi.string().optional(), // TODO remove in 2.8 teardown: joi.string().optional(), // TODO remove in 2.8 tests: ( - joi.array().optional() - .items(joi.string().required()) + joi.alternatives() + .try( + joi.string().required(), + ( + joi.array().optional() + .items(joi.string().required()) + .default(Array, 'empty test files array') + ) + ) ), thumbnail: joi.string().optional(), version: joi.string().required(), @@ -352,6 +359,14 @@ var checkManifest = function(filename, manifest) { } }); + if (typeof manifest.controllers === 'string') { + manifest.controllers = {'/': manifest.controllers}; + } + + if (typeof manifest.tests === 'string') { + manifest.tests = [manifest.tests]; + } + if (!valid) { throw new ArangoError({ errorNum: errors.ERROR_INVALID_APPLICATION_MANIFEST.code, diff --git a/js/server/modules/org/arangodb/foxx/routing.js b/js/server/modules/org/arangodb/foxx/routing.js index f641fea1e2..f7e5d7b972 100644 --- a/js/server/modules/org/arangodb/foxx/routing.js +++ b/js/server/modules/org/arangodb/foxx/routing.js @@ -634,9 +634,7 @@ function escapeHTML (string) { var controllers = app._manifest.controllers; try { - if (typeof controllers === "string") { - mountController(app, routes, "/", controllers); - } else if (controllers) { + if (controllers) { Object.keys(controllers).forEach(function (key) { mountController(app, routes, key, controllers[key]); });