Skip to main content

Quick Start

Before proceeding, make sure to install express, mongoose and @egose/acl as peer dependencies. These packages are required for the proper functioning of the application and must be installed prior to running the code. You can install them using the npm package manager.

Installation​

npm install express mongoose @egose/swagger
npm install @types/express --save-dev

Backend Configuration​

Bootstrapping the Swagger routes in an Express Server​

import mongoose from 'mongoose';
import express from 'express';
import egose from '@egose/acl';
import { createOpenAPI } from '@egose/swagger';

const app = express();
const router = express.Router();

const UserSchema = new mongoose.Schema({
name: { type: String },
});

mongoose.model('User', UserSchema);

const userRouter = egose.createRouter('User', { parentPath: '/api', basePath: '/users' });

const swagger = createOpenAPI([userRouter], { baseUrl: 'http://localhost:3000' });

router.use('/', userRouter.routes);
router.use('/api-docs', swagger.serve);
router.get('/api-docs', swagger.setup);

app.use('/api', router);

app.listen(3000);