-
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apidocs): Autogenerate OpenAPI docs ZMS-100 (#552)
* api.js added endpoint for generating openapi docs. added new info to one route in mailboxes.js and messages.js files so that the api docs generation can be done at all * try to first generate json representation of the api docs * add initial Joi Object parsing * api.js make generation dynamic. messages.js add schemas from separate file. messages-schemas.js used for messages endpoint schemas * add additions to schemas. Add new schemas to messages.js and also add response object there. Add response object parsing functionality to api.js * add initial openapi doc yml file generation * remove manual yaml parsing with js-yaml JSON -> YAML parsing * fix replaceWithRefs and parseComponentsDecoupled functions, refactor, remove unnecessary comments and logs * add support for another endpoint * move big code from api.js to tools * fix array type representation, fix response objects, add necessary data and changes to endpoints * redo include logic into exclude login * fix api generation in tools.js to accomodate new naming of objects * fix messages.js, add structuredClone check in tools.js * fix structured clone definition * add one endpoint in messages.js to the api generation * messages.js add one more endpoint to API generation * add response to prev commit. Add new endpoint to API generation. Archive message and archive messages * finish with post endpoints in messages.js * added general request and response schemas. Also added req and res schemas for messages * add multiple GET endpoints to API generation and changed them to new design. Use general schemas made earlier * fix incorrect import of successRes * fix mailboxes.js * refactor general-schemas.js. Fix searchSchema in messages.js. Mailboxes.js fix response * tools.js rename methodObj in API generation to operationObj * tools.js api generation remove string fallbacks * messages.js finish with GET endpoints, addition to API doc generation * for openApi doc generation use JSON now instead of YAML
- Loading branch information
Showing
9 changed files
with
1,339 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
const Joi = require('joi'); | ||
|
||
const userId = Joi.string().hex().lowercase().length(24).required().description('ID of the User'); | ||
const mailboxId = Joi.string().hex().lowercase().length(24).required().description('ID of the Mailbox'); | ||
const messageId = Joi.number().min(1).required().description('Message ID'); | ||
|
||
module.exports = { | ||
userId, | ||
mailboxId, | ||
messageId | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
const Joi = require('joi'); | ||
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.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), | ||
contentType: Joi.string().empty('').max(255), | ||
encoding: Joi.string().empty('').default('base64'), | ||
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(), | ||
id: Joi.number().required(), | ||
action: Joi.string().valid('reply', 'replyAll', 'forward').required(), | ||
attachments: Joi.alternatives().try( | ||
booleanSchema, | ||
Joi.array().items( | ||
Joi.string() | ||
.regex(/^ATT\d+$/i) | ||
.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, | ||
AddressOptionalNameArray, | ||
Header, | ||
Attachment, | ||
ReferenceWithAttachments, | ||
Bimi | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
const { booleanSchema } = require('../../schemas'); | ||
|
||
const successRes = booleanSchema.required().description('Indicates successful response'); | ||
|
||
module.exports = { | ||
successRes | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
const Joi = require('joi'); | ||
|
||
const Rcpt = Joi.object({ | ||
value: Joi.string().required().description('RCPT TO address as provided by SMTP client'), | ||
formatted: Joi.string().required().description('Normalized RCPT address') | ||
}).$_setFlag('objectName', 'Rcpt'); | ||
|
||
const MsgEnvelope = Joi.object({ | ||
from: Joi.string().required().description('Address from MAIL FROM'), | ||
rcpt: Joi.array().items(Rcpt).description('Array of addresses from RCPT TO (should have just one normally)') | ||
}) | ||
.description('SMTP envelope (if available)') | ||
.$_setFlag('objectName', 'Envelope'); | ||
|
||
module.exports = { | ||
MsgEnvelope | ||
}; |
Oops, something went wrong.