Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: serve openapi.yaml file as documentation page #73

Merged
merged 10 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"cors": "^2.8.5",
"express": "^4.17.1",
"js-yaml": "^4.1.0",
"redoc-express": "^1.0.0",
"uuid": "^8.3.2",
"winston": "^3.3.3"
},
Expand Down
34 changes: 34 additions & 0 deletions src/controllers/docs.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { NextFunction, Request, Response, Router } from 'express';
BOLT04 marked this conversation as resolved.
Show resolved Hide resolved

import redoc from 'redoc-express';

import { Controller } from '../interfaces';

export class DocsController implements Controller {
public basepath = '/docs';

private async docs(req: Request, res: Response, next: NextFunction) {
try {

await redoc({
title: 'API Docs',
specUrl: '.../openapi.yaml'
});

res.status(204).end();
} catch (err) {
return next(err);
}
}
BOLT04 marked this conversation as resolved.
Show resolved Hide resolved

public boot(): Router {
const router = Router();

router.post(
`${this.basepath}`,
this.docs.bind(this)
);

return router;
}
}
4 changes: 3 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ process.env['NODE_CONFIG_DIR'] = `${__dirname }/configs`;
import { App } from './app';
import { GenerateController } from './controllers/generate.controller';
import { ValidateController } from './controllers/validate.controller';
import { DocsController } from './controllers/docs.controller';

const app = new App([
new GenerateController(),
new ValidateController()
new ValidateController(),
new DocsController()
]);
app.listen();