diff --git a/api.js b/api.js index 8e42370a..365ec88f 100644 --- a/api.js +++ b/api.js @@ -737,6 +737,7 @@ module.exports = done => { }, required: true }; + for (const reqBodyKey in spec.requestBody) { const reqBodyKeyData = spec.requestBody[reqBodyKey]; @@ -757,8 +758,6 @@ module.exports = done => { obj.description = paramKeyData._flags.description || ''; obj.required = paramKeyData._flags.presence === 'required'; obj.schema = { type: paramKeyData.type }; - - // console.log(paramKeyData); } for (const paramKey in spec.queryParams) { @@ -774,6 +773,14 @@ module.exports = done => { // 7) add responses methodObj.responses = {}; + + for (const resHttpCode in spec.response) { + const restBodyData = spec.response[resHttpCode]; + + parseJoiObject(resHttpCode, restBodyData, methodObj.responses); + } + + console.log(methodObj.responses); } }) ); @@ -789,18 +796,25 @@ module.exports = done => { binary: 'string' }; + /** + * Parse Joi Objects + */ function parseJoiObject(path, joiObject, requestBodyProperties) { - // console.log(path, joiObject, requestBody); if (joiObject.type === 'object') { // recursion const fieldsMap = joiObject._ids._byKey; const data = { type: joiObject.type, - descrption: joiObject._flags.description || '', + description: joiObject._flags.description || '', properties: {}, required: [] }; + + if (joiObject._flags.objectName) { + data.objectName = joiObject._flags.objectName; + } + if (path) { requestBodyProperties[path] = data; } else { @@ -863,9 +877,9 @@ module.exports = done => { } // TODO: if type before and after is string, add additional checks - if (openApiType === 'string') { - console.log(joiObject._rules); - } + // if (openApiType === 'string') { + // console.log(joiObject._rules); + // } const data = { type: openApiType, description, required: isRequired }; if (format) { diff --git a/lib/api/messages.js b/lib/api/messages.js index d6204035..466adfd2 100644 --- a/lib/api/messages.js +++ b/lib/api/messages.js @@ -25,7 +25,7 @@ const { getMongoDBQuery /*, getElasticSearchQuery*/ } = require('../search-query //const { getClient } = require('../elasticsearch'); const BimiHandler = require('../bimi-handler'); -const { Address, AddressOptionalName, Header, Attachment, ReferenceWithAttachments, Bimi } = require('../schemas/request/messages-schemas'); +const { Address, AddressOptionalNameArray, Header, Attachment, ReferenceWithAttachments, Bimi } = require('../schemas/request/messages-schemas'); module.exports = (db, server, messageHandler, userHandler, storageHandler, settingsHandler) => { let maildrop = new Maildropper({ @@ -1551,11 +1551,11 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti replyTo: Address, - to: AddressOptionalName, + to: AddressOptionalNameArray, - cc: AddressOptionalName, + cc: AddressOptionalNameArray, - bcc: AddressOptionalName, + bcc: AddressOptionalNameArray, headers: Joi.array().items(Header), @@ -1588,7 +1588,18 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti ip: sessIPSchema }, queryParams: {}, - tags: ['Messages'] + tags: ['Messages'], + response: { + 200: Joi.object({ + success: Joi.boolean(), + message: Joi.object({ + id: Joi.number(), + malbox: Joi.string(), + size: Joi.number() + }), + previousDeleted: Joi.boolean() + }) + } }, tools.responseWrapper(async (req, res) => { res.charSet('utf-8'); diff --git a/lib/schemas/request/messages-schemas.js b/lib/schemas/request/messages-schemas.js index 9a948613..d4226e60 100644 --- a/lib/schemas/request/messages-schemas.js +++ b/lib/schemas/request/messages-schemas.js @@ -6,21 +6,21 @@ const { booleanSchema } = require('../../schemas'); const Address = Joi.object({ name: Joi.string().empty('').max(255), address: Joi.string().email({ tlds: false }).required() -}); +}).$_setFlag('objectName', 'Address'); -const AddressOptionalName = Joi.array().items( - Joi.object({ - name: Joi.string().empty('').max(255), - address: Joi.string().email({ tlds: false }).required() - }) -); +const AddressOptionalName = Joi.object({ + name: Joi.string().empty('').max(255), + address: Joi.string().email({ tlds: false }).required() +}).$_setFlag('objectName', 'AddressOptionalName'); + +const AddressOptionalNameArray = Joi.array().items(AddressOptionalName); const Header = Joi.object({ key: Joi.string().empty('').max(255), value: Joi.string() .empty('') .max(100 * 1024) -}); +}).$_setFlag('objectName', 'Header'); const Attachment = Joi.object({ filename: Joi.string().empty('').max(255), @@ -29,7 +29,7 @@ const Attachment = Joi.object({ contentTransferEncoding: Joi.string().empty(''), content: Joi.string().required(), cid: Joi.string().empty('').max(255) -}); +}).$_setFlag('objectName', 'Attachment'); const ReferenceWithAttachments = Joi.object({ mailbox: Joi.string().hex().lowercase().length(24).required(), @@ -43,16 +43,16 @@ const ReferenceWithAttachments = Joi.object({ .uppercase() ) ) -}); +}).$_setFlag('objectName', 'ReferenceWithAttachments'); const Bimi = Joi.object({ domain: Joi.string().domain().required(), selector: Joi.string().empty('').max(255) -}); +}).$_setFlag('objectName', 'Bimi'); module.exports = { Address, - AddressOptionalName, + AddressOptionalNameArray, Header, Attachment, ReferenceWithAttachments,