From b9d4a966523c1e3726c3cd9c4a830cc1874f2d54 Mon Sep 17 00:00:00 2001 From: Lucas Dohmen Date: Wed, 18 Jun 2014 17:31:11 +0200 Subject: [PATCH] Add simple documentation for methods without bodyParam post, put and patch requests without a bodyParam will now be documented with an undocumented bodyParam. This will allow people to try out this undocumented field in the Swagger documentation in the admin interface. --- .../modules/org/arangodb/foxx/controller.js | 5 +++++ .../org/arangodb/foxx/request_context.js | 20 ++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/js/server/modules/org/arangodb/foxx/controller.js b/js/server/modules/org/arangodb/foxx/controller.js index 1e9afa4b67..eda6f33cc7 100644 --- a/js/server/modules/org/arangodb/foxx/controller.js +++ b/js/server/modules/org/arangodb/foxx/controller.js @@ -174,6 +174,11 @@ extend(Controller.prototype, { this.applicationContext.clearComments(); + if (method === 'post' || method === 'put' || method === 'patch') { + var UndocumentedBody = require('org/arangodb/foxx').Model.extend(); + requestContext.bodyParam("undocumented body", "Undocumented body param", UndocumentedBody); + } + return requestContext; }, diff --git a/js/server/modules/org/arangodb/foxx/request_context.js b/js/server/modules/org/arangodb/foxx/request_context.js index f5adf07012..a7b10897ef 100644 --- a/js/server/modules/org/arangodb/foxx/request_context.js +++ b/js/server/modules/org/arangodb/foxx/request_context.js @@ -144,12 +144,22 @@ extend(SwaggerDocs.prototype, { 'use strict'; this.models[jsonSchema.id] = jsonSchema; - this.docs.parameters.push({ - name: paramName, - paramType: "body", - description: description, - dataType: jsonSchema.id + var param = _.find(this.docs.parameters, function (parameter) { + return parameter.name === 'undocumented body'; }); + + if (_.isUndefined(param)) { + this.docs.parameters.push({ + name: paramName, + paramType: "body", + description: description, + dataType: jsonSchema.id + }); + } else { + param.name = paramName; + param.description = description; + param.dataType = jsonSchema.id; + } }, addSummary: function (summary) {