Skip to content

Commit

Permalink
fix circular references
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu committed Mar 29, 2022
1 parent 9c32793 commit b739691
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 41 deletions.
24 changes: 0 additions & 24 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ components:
optional:
- base
properties:
<<<<<<< master
asyncapi:
$ref: '#/components/schemas/AsyncAPIDocument'
version:
Expand All @@ -282,15 +281,12 @@ components:
required:
- asyncapis
properties:
=======
>>>>>>> removed parser and validate, added optional field in openapi.yaml
asyncapis:
type: array
minItems: 1
items:
$ref: "#/components/schemas/AsyncAPIDocument"
base:
<<<<<<< master
$ref: "#/components/schemas/AsyncAPIDocument"
x-server-api:
skipFieldsInValidation: [asyncapis, base]
Expand All @@ -301,26 +297,6 @@ components:
properties:
bundled:
$ref: "#/components/schemas/AsyncAPIDocument"
=======
type: string
description: Base directory to be used for bundling.
default: "."
Bundle:
type: object
required:
- asyncapis
optional:
- base
properties:
asyncapis:
type: array
items:
$ref: "#/components/schemas/AsyncAPIDocument"
base:
type: string
description: Base directory to be used for bundling.
default: "."
>>>>>>> removed parser and validate, added optional field in openapi.yaml
Problem:
type: object
properties:
Expand Down
47 changes: 47 additions & 0 deletions package-lock.json

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

11 changes: 6 additions & 5 deletions src/controllers/bundler.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { NextFunction, Request, Response, Router } from 'express';
import { ProblemException } from '../exceptions/problem.exception';
import { Controller } from '../interfaces';
import bundler from '@asyncapi/bundler';
import Document from '@asyncapi/bundler/lib/document.js';
import { documentValidationMiddleware } from '../middlewares/document-validation.middleware';
import path from 'path';

export class BundlerController implements Controller {
public basepath = '/bundle';
private async bundle(req: Request, res: Response, next: NextFunction) {
const asyncapis: Array<string> = req.body.asyncapis || [req.body.asyncapi];
const asyncapis: Array<string> = req.body.asyncapis;
const base = req.body.base;

try {
const document = await bundler.bundle(asyncapis, { base: path.dirname(asyncapis[0]) });
const doc = new Document(document).json();
res.status(200).json(doc);
const document = await bundler(asyncapis, { base });
const bundled = document.json();
res.status(200).json({ bundled });
} catch (err) {
return next(new ProblemException({
type: 'internal-bundler-error',
Expand Down
60 changes: 48 additions & 12 deletions src/controllers/tests/bundler.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('BundlerController', () => {
describe('[POST] /bundle', () => {
it('should bundle files', async () => {
const app = new App([new BundlerController()]);
const response = await request(app.getServer())
await request(app.getServer())
.post('/v1/bundle')
.send({
asyncapis: [{
Expand All @@ -17,30 +17,66 @@ describe('BundlerController', () => {
title: 'Test Service',
version: '1.0.0',
},
servers: {},
channels: {
'test-channel': {
messages: {
'test-message': {
'test-channel-2': {
publish: {
message: {
payload: {
type: 'object',
},
},
},
}
},
},
}],
base: {
asyncapi: '2.2.0',
info: {
title: 'Test Service',
version: '1.0.0',
title: 'Merged test service',
version: '1.2.0',
},
channels: {},
servers: {},
channels: {
'test-channel-1': {
publish: {
message: {
payload: {
type: 'object',
},
},
}
},
},
}
}).
expect(200, {
bundled: {
asyncapi: '2.2.0',
info: { title: 'Merged test service', version: '1.2.0' },
servers: {},
channels: {
'test-channel-1': {
publish: {
message: {
payload: {
type: 'object',
},
},
}
},
'test-channel-2': {
publish: {
message: {
payload: {
type: 'object',
},
},
}
},
}
}
})
.set('Accept', 'application/json');
expect(response.headers['content-type']).toBe('application/json; charset=utf-8');
expect(response.status).toBe(200);
});
});
});
});

0 comments on commit b739691

Please sign in to comment.