diff --git a/ghost/api-framework/lib/frame.js b/ghost/api-framework/lib/frame.js index b91de8dc86..2be8cb3b74 100644 --- a/ghost/api-framework/lib/frame.js +++ b/ghost/api-framework/lib/frame.js @@ -19,6 +19,8 @@ class Frame { * file: Uploaded file * files: Uploaded files * apiType: Content or admin api access + * docName: The endpoint name, e.g. "posts" + * method: The method name, e.g. "browse" */ this.options = {}; this.data = {}; @@ -26,6 +28,9 @@ class Frame { this.file = {}; this.files = []; this.apiType = null; + this.docName = null; + this.method = null; + this.response = null; } /** diff --git a/ghost/api-framework/lib/pipeline.js b/ghost/api-framework/lib/pipeline.js index f5300ae004..81f2120dd7 100644 --- a/ghost/api-framework/lib/pipeline.js +++ b/ghost/api-framework/lib/pipeline.js @@ -174,23 +174,21 @@ const STAGES = { * 4. Controller - Execute the controller implementation & receive model response. * 5. Output Serialisation - Output formatting, Deprecations, Extra attributes etc... * - * @param {Function} apiController + * @param {Object} apiController * @param {Object} apiUtils - Local utils (validation & serialisation) from target API version * @param {String} [apiType] - Content or Admin API access - * @return {Function} + * @return {Object} */ const pipeline = (apiController, apiUtils, apiType) => { const keys = Object.keys(apiController); + const docName = apiController.docName; // CASE: api controllers are objects with configuration. // We have to ensure that we expose a functional interface e.g. `api.posts.add` has to be available. - return keys.reduce((obj, key) => { - const docName = apiController.docName; - const method = key; + return keys.reduce((obj, method) => { + const apiImpl = _.cloneDeep(apiController)[method]; - const apiImpl = _.cloneDeep(apiController)[key]; - - obj[key] = function wrapper() { + obj[method] = function wrapper() { const apiConfig = {docName, method}; let options; let data; @@ -253,7 +251,7 @@ const pipeline = (apiController, apiUtils, apiType) => { }); }; - Object.assign(obj[key], apiImpl); + Object.assign(obj[method], apiImpl); return obj; }, {}); }; diff --git a/ghost/api-framework/test/frame.test.js b/ghost/api-framework/test/frame.test.js index 36e134497f..c53eb2dc1c 100644 --- a/ghost/api-framework/test/frame.test.js +++ b/ghost/api-framework/test/frame.test.js @@ -11,7 +11,10 @@ describe('Frame', function () { 'user', 'file', 'files', - 'apiType' + 'apiType', + 'docName', + 'method', + 'response' ]); }); diff --git a/ghost/api-framework/test/http.test.js b/ghost/api-framework/test/http.test.js index bfb8b86b43..ad7a038161 100644 --- a/ghost/api-framework/test/http.test.js +++ b/ghost/api-framework/test/http.test.js @@ -45,7 +45,10 @@ describe('HTTP', function () { 'user', 'file', 'files', - 'apiType' + 'apiType', + 'docName', + 'method', + 'response' ]); apiImpl.args[0][0].data.should.eql({a: 'a'});