forked from asyncapi/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.controller.ts
More file actions
45 lines (37 loc) · 1.13 KB
/
Copy pathdiff.controller.ts
File metadata and controls
45 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { NextFunction, Request, Response, Router } from 'express';
import { diff } from '@asyncapi/diff';
import { validationMiddleware } from '../middlewares/validation.middleware';
import { ProblemException } from '../exceptions/problem.exception';
import { Controller } from '@/interfaces';
export class DiffController implements Controller {
public basepath = '/diff';
private async diff(req: Request, res: Response, next: NextFunction) {
const { asyncapis } = req.body;
try {
const output = diff(asyncapis[0], asyncapis[1]).getOutput();
res.status(200).json({ diff: output });
} catch (err) {
return next(
new ProblemException({
type: 'internal-diff-error',
title: 'Internal Diff error',
status: 500,
detail: (err as Error).message,
}),
);
}
}
public async boot(): Promise<Router> {
const router = Router();
router.post(
this.basepath,
await validationMiddleware({
path: this.basepath,
method: 'post',
documents: ['asyncapis'],
}),
this.diff.bind(this),
);
return router;
}
}