Skip to content

Commit

Permalink
fix(api-generate): Move API generation code into separate package and…
Browse files Browse the repository at this point in the history
… use it ZMS-119 (#613)

* test initial design of API generation as a restify plugin. next extract it into separate npm package and add more checks/logs etc.

* remove API docs generation from the WILDDUCK specific tools.js file into a separate file. Do appropriate changes

* move api generation into separate npm package, currently local

* add restifyapigenerate package and use it, fix path

* separate API docs generation config into a separate file. Fix API docs generation package version
  • Loading branch information
NickOvt committed Feb 5, 2024
1 parent 630b751 commit c7a1ab4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 437 deletions.
14 changes: 4 additions & 10 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const settingsRoutes = require('./lib/api/settings');
const healthRoutes = require('./lib/api/health');
const { SettingsHandler } = require('./lib/settings-handler');

const restifyApiGenerate = require('restifyapigenerate');
const restifyApiGenerateConfig = require('./config/apigeneration.json');

let userHandler;
let mailboxHandler;
let messageHandler;
Expand Down Expand Up @@ -575,16 +578,7 @@ module.exports = done => {
);
}

server.get(
{ path: '/openapi', name: 'openapi-docs-generation' },
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const routes = server.router.getRoutes();

tools.generateAPiDocs(routes);
})
);
server.pre(restifyApiGenerate(server, restifyApiGenerateConfig));

server.on('error', err => {
if (!started) {
Expand Down
68 changes: 68 additions & 0 deletions config/apigeneration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"openapiVersion": "3.0.0",
"info": {
"title": "WildDuck API",
"description": "WildDuck API docs",
"version": "1.0.0",
"contact": {
"url": "https://github.com/nodemailer/wildduck"
}
},
"servers": [{ "url": "https://api.wildduck.email" }],
"tags": [
{ "name": "Addresses" },
{ "name": "ApplicationPasswords" },
{
"name": "Archive",
"description":
"Archive includes all deleted messages. Once messages are old enough then these are permanenetly deleted from the archive as well. Until then you can restore the deleted messages."
},
{
"name": "Audit",
"description":
"Auditing allows to monitor an email account. All existing, deleted and new emails are copied to the auditing system. See also https://github.com/nodemailer/wildduck-audit-manager"
},
{ "name": "Authentication" },
{ "name": "Autoreplies" },
{
"name": "Certs",
"description":
"WildDuck allows to register TLS certificates to be used with SNI connections. These certificates are used by IMAP, POP3, API and SMTP servers when a SNI capable client establishes a TLS connection. This does not apply for MX servers."
},
{
"name": "DKIM",
"description":
"Whenever an email is sent WildDuck checks if there is a DKIM key registered for the domain name of the sender address and uses it to sign the message."
},
{
"name": "DomainAccess",
"description": "Add sender domain names to allowlist (messages are all accepted) or blocklist (messages are sent to Spam folder)"
},
{ "name": "DomainAliases" },
{ "name": "Filters" },
{ "name": "Mailboxes" },
{ "name": "Messages" },
{ "name": "Settings" },
{
"name": "Storage",
"description":
"Storage allows easier attachment handling when composing Draft messages. Instead of uploading the attachmnent with every draft update, you store the attachment to the Storage and then link stored file for the Draft."
},
{ "name": "Submission" },
{ "name": "TwoFactorAuth" },
{ "name": "Users" },
{ "name": "Webhooks" }
],
"components": {
"securitySchemes": {
"AccessTokenAuth": {
"name": "X-Access-Token",
"type": "apiKey",
"in": "header",
"description": "If authentication is enabled in the WildDuck configuration, you will need to supply an access token in the `X-Access-Token` header.\n```json\n{\n \"X-Access-Token\": \"59fc66a03e54454869460e45\"\n}\n```\n"
}
}
},
"security": [{ "AccessTokenAuth": [] }],
"docsPath": "/../../openapidocs.json"
}
Loading

0 comments on commit c7a1ab4

Please sign in to comment.