Skip to content

Commit

Permalink
Feat: Set API Docs (#25)
Browse files Browse the repository at this point in the history
* set api docs

* change title

* add feature flag

* add swagger path config

Co-authored-by: BagusAK95 <[email protected]>
  • Loading branch information
BagusAK95 and BagusAK95 authored Apr 19, 2021
1 parent 6ba2d4e commit 566e0ad
Show file tree
Hide file tree
Showing 3 changed files with 5,068 additions and 38 deletions.
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const express = require("express");
const bodyParser = require("body-parser");
const router = require("./lib/router");
const getfn = require("./lib/getfn");
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');

module.exports = function (merapi) {

Expand All @@ -26,6 +28,22 @@ module.exports = function (merapi) {
let bodyParserOptions = cfg.bodyParser || {};
let middleware = cfg.middleware || [];
let routes = cfg.routes || {};
let swaggerEnable = (cfg.swagger && cfg.swagger.enable) ? cfg.swagger.enable : false
if (swaggerEnable) {
let swaggerPath = cfg.swagger.path || '/api-docs';
let swaggerInfo = cfg.swagger.info || {
title: 'API Documentation',
version: '1.0.0',
};
let swaggerSpec = swaggerJsdoc({
definition: {
openapi: '3.0.0',
info: swaggerInfo,
},
apis: ['./components/controllers/*_controller.ts', './components/managers/*_manager.ts', './components/swagger/*.yaml'],
});
app.use(swaggerPath, swaggerUi.serve, swaggerUi.setup(swaggerSpec));
}

if (bodyParserOptions.verify) {
bodyParserOptions.verify = yield getFn(bodyParserOptions.verify);
Expand Down
Loading

0 comments on commit 566e0ad

Please sign in to comment.