legendaryjs
Version:
LegendaryJS – The ultimate backend framework for speed, power, and simplicity.
38 lines (32 loc) • 815 B
JavaScript
const fs = require('fs');
const path = require('path');
const swagger = {
openapi: '3.0.0',
info: {
title: 'LegendaryJS API',
version: '1.0.0'
},
paths: {}
};
function addRouteToDocs({ method, path, description, auth }) {
if (!swagger.paths[path]) swagger.paths[path] = {};
swagger.paths[path][method.toLowerCase()] = {
summary: description || `Route for ${path}`,
security: auth ? [{ bearerAuth: [] }] : [],
responses: {
200: { description: 'Success' },
400: { description: 'Bad Request' }
}
};
fs.writeFileSync(
pathResolve('/docs/legendary.json'),
JSON.stringify(swagger, null, 2)
);
}
function pathResolve(file) {
return path.join(process.cwd(), file);
}
module.exports = {
swagger,
addRouteToDocs
};