Skip to content

Commit

Permalink
fix: resolve external references in base file (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Souvikns committed Nov 29, 2022
1 parent ba54aa3 commit b4a0224
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/index.ts
@@ -1,5 +1,6 @@
import { toJS, resolve } from './util';
import { Document } from './document';
import { parse } from './parser';

import type { AsyncAPIObject } from './spec-types';

Expand Down Expand Up @@ -73,6 +74,7 @@ import type { AsyncAPIObject } from './spec-types';
export default async function bundle(files: string[], options: any = {}) {
if (typeof options.base !== 'undefined') {
options.base = toJS(options.base);
await parse(options.base);
}

const parsedJsons = files.map(file => toJS(file)) as AsyncAPIObject[];
Expand Down
33 changes: 33 additions & 0 deletions tests/base-option/asyncapi.yaml
@@ -0,0 +1,33 @@
asyncapi: 2.5.0
info:
title: Smart home applicance service
version: 2.0.0
description: This is a API for contolling various smart appliance
channels:
lights/On:
subcribe:
message:
$ref: '#/components/messages/LightsOn'
camera/click:
subcribe:
message:
$ref: '#/components/messages/clickPhoto'
components:
messages:
LightsOn:
payload:
type: object
properties:
sourceId:
type: string
voltage:
type: number
clickPhoto:
type: object
properties:
bustMode:
type: boolean
zoomDepth:
type: number
delayTimer:
type: number
5 changes: 5 additions & 0 deletions tests/base-option/base.yaml
@@ -0,0 +1,5 @@
asyncapi: "2.5.0"
info:
title: Smart home applicance service
version: 2.0.0
description: This is a API for contolling various smart appliance
10 changes: 10 additions & 0 deletions tests/base-option/camera.yaml
@@ -0,0 +1,10 @@
asyncapi: "2.5.0"
info:
title: Camera Service
version: 2.0.0
description: This service is in charge of for controlling Camera functions
channels:
camera/click:
subcribe:
message:
$ref: './tests/base-option/messages.yaml#/messages/clickPhoto'
10 changes: 10 additions & 0 deletions tests/base-option/lights.yaml
@@ -0,0 +1,10 @@
asyncapi: "2.5.0"
info:
title: Lights Service
version: 1.0.0
description: This service is in charge of for controlling lights
channels:
lights/On:
subcribe:
message:
$ref: './tests/base-option/messages.yaml#/messages/LightsOn'
18 changes: 18 additions & 0 deletions tests/base-option/messages.yaml
@@ -0,0 +1,18 @@
messages:
LightsOn:
payload:
type: object
properties:
sourceId:
type: string
voltage:
type: number
clickPhoto:
type: object
properties:
bustMode:
type: boolean
zoomDepth:
type: number
delayTimer:
type: number
14 changes: 13 additions & 1 deletion tests/lib/index.spec.ts
Expand Up @@ -21,7 +21,7 @@ describe('[integration testing] bundler should ', () => {
validate: false,
}
);

expect(response).toBeDefined();
});

Expand Down Expand Up @@ -77,6 +77,18 @@ describe('[integration testing] bundler should ', () => {
)
).resolves;
});

test('should be able to bundle base file', async () => {
const files = ['./tests/base-option/lights.yaml', './tests/base-option/camera.yaml']

expect(
await bundle(
files.map(file => fs.readFileSync(path.resolve(process.cwd(), file), 'utf-8')),
{ referenceIntoComponents: true, base: fs.readFileSync(path.resolve(process.cwd(), './tests/base-option/base.yaml'), 'utf-8') }
)
).resolves;

})
});

describe('[unit testing]', () => {
Expand Down

0 comments on commit b4a0224

Please sign in to comment.