1
0
Fork 0

Fix swagger responses

This commit is contained in:
Alan Plum 2016-02-03 16:34:37 +01:00
parent 6bc2a10867
commit b01a3da328
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
1 changed files with 11 additions and 8 deletions

View File

@ -31,7 +31,7 @@ const tokenize = require('@arangodb/foxx/router/tokenize');
const MIME_JSON = 'application/json; charset=utf-8';
const MIME_BINARY = 'application/octet-stream';
const DEFAULT_BODY_SCHEMA = joi.object().optional().meta({allowInvalid: true});
const DEFAULT_BODY_SCHEMA = joi.object().unknown().meta({allowInvalid: true}).optional();
const DEFAULT_ERROR_SCHEMA = joi.object().keys({
error: joi.allow(true).required(),
errorNum: joi.number().integer().optional(),
@ -175,12 +175,10 @@ module.exports = exports = class SwaggerContext {
statusCode = 200;
}
if (model === null) {
if (statusCode === 200) {
if (model === null && statusCode === 200) {
this._responses.delete(200);
statusCode = 204;
}
}
if (
typeof model === 'string'
@ -460,7 +458,7 @@ module.exports = exports = class SwaggerContext {
: null
);
const response = {};
if (def.contentTypes) {
if (def.contentTypes && def.contentTypes.length) {
response.schema = (
schema
? joi2schema(schema.isJoi ? schema : joi.object(schema), def.multiple)
@ -469,12 +467,17 @@ module.exports = exports = class SwaggerContext {
}
if (schema && schema._description) {
response.description = schema._description;
delete response.schema.description;
}
if (def.description) {
response.description = def.description;
}
if (!response.description) {
response.description = `The ${code} response body.`;
if (response.schema) {
response.description = `Undocumented ${code} response`;
} else {
response.description = `No ${code} response body`;
}
}
operation.responses[code] = response;
}