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

fix: update @asyncapi/bundler to 0.5.0 version #1415

Merged
merged 5 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 6 additions & 17 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bugs": "https://github.com/asyncapi/cli/issues",
"dependencies": {
"@asyncapi/avro-schema-parser": "^3.0.22",
"@asyncapi/bundler": "^0.4.0",
"@asyncapi/bundler": "^0.5.0",
"@asyncapi/converter": "^1.4.19",
"@asyncapi/diff": "^0.4.1",
"@asyncapi/generator": "^1.17.25",
Expand Down
44 changes: 15 additions & 29 deletions src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,44 @@ import Command from '../base';
import bundle from '@asyncapi/bundler';
import { promises } from 'fs';
import path from 'path';
import { Specification, load } from '../models/SpecificationFile';
import { Parser } from '@asyncapi/parser';
import { Specification } from '../models/SpecificationFile';
import { Document } from '@asyncapi/bundler/lib/document';

const { writeFile } = promises;

export default class Bundle extends Command {
static description = 'bundle one or multiple asyncapi documents and their references together.';
static readonly description = 'Bundle one or multiple AsyncAPI Documents and their references together.';
static strict = false;

static examples: Example[] = [
'asyncapi bundle ./asyncapi.yaml > final-asyncapi.yaml',
'asyncapi bundle ./asyncapi.yaml --output final-asyncapi.yaml',
'asyncapi bundle ./asyncapi.yaml ./features.yaml --reference-into-components',
'asyncapi bundle ./asyncapi.yaml ./features.yaml --base ./asyncapi.yaml --reference-into-components'
'asyncapi bundle ./asyncapi.yaml ./features.yaml',
'asyncapi bundle ./asyncapi.yaml ./features.yaml --base ./main.yaml',
'asyncapi bundle ./asyncapi.yaml ./features.yaml --base ./main.yaml --xOrigin',
'asyncapi bundle ./asyncapi.yaml -o final-asyncapi.yaml --base ../public-api/main.yaml --baseDir ./social-media/comments-service',
];

static flags = {
help: Flags.help({ char: 'h' }),
output: Flags.string({ char: 'o', description: 'The output file name. Omitting this flag the result will be printed in the console.' }),
'reference-into-components': Flags.boolean({ char: 'r', description: 'Bundle the message $refs into components object.' }),
base: Flags.string({ char: 'b', description: 'Path to the file which will act as a base. This is required when some properties are to needed to be overwritten.' }),
base: Flags.string({ char: 'b', description: 'Path to the file which will act as a base. This is required when some properties need to be overwritten.' }),
baseDir: Flags.string({ char: 'd', description: 'One relative/absolute path to directory relative to which paths to AsyncAPI Documents that should be bundled will be resolved.' }),
xOrigin: Flags.boolean({ char: 'x', description: 'Pass this switch to generate properties "x-origin" that will contain historical values of dereferenced "$ref"s.' }),
};

parser = new Parser();

async run() {
const { argv, flags } = await this.parse(Bundle);
const output = flags.output;
let baseFile;
const outputFormat = path.extname(argv[0]);
const AsyncAPIFiles = await this.loadFiles(argv);

this.metricsMetadata.files = AsyncAPIFiles.length;

if (flags.base) {baseFile = (await load(flags.base)).text();}
const AsyncAPIFiles = argv;

const fileContents = AsyncAPIFiles.map((file) => file.text());
this.metricsMetadata.files = AsyncAPIFiles.length;

const document = await bundle(fileContents,
const document = await bundle(AsyncAPIFiles,
{
referenceIntoComponents: flags['reference-into-components'],
base: baseFile
base: flags.base,
baseDir: flags.baseDir,
xOrigin: flags.xOrigin,
}
);

Expand Down Expand Up @@ -86,13 +81,4 @@ export default class Bundle extends Command {
}
}
}

async loadFiles(filepaths: string[]): Promise<Specification[]> {
const files = [];
for (const filepath of filepaths) {
const file = await load(filepath);
files.push(file);
}
return files;
}
}
1 change: 0 additions & 1 deletion src/models/SpecificationFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,3 @@ async function detectSpecFile(): Promise<string | undefined> {
}));
return existingFileNames.find(filename => filename !== undefined);
}

17 changes: 3 additions & 14 deletions test/integration/bundle/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,14 @@ describe('bundle', () => {
'bundle', './test/integration/bundle/asyncapi.yml'
])
.it('should throw error message if the file path is wrong', (ctx, done) => {
expect(ctx.stderr).to.contain('error loading AsyncAPI document from file: ./test/integration/bundle/asyncapi.yml file does not exist.\n');
expect(ctx.stderr).to.contain('Error: ENOENT: no such file or directory');
done();
});

test
.stdout()
.command([
'bundle', './test/integration/bundle/first-asyncapi.yaml', '--reference-into-components', '--output=./test/integration/bundle/final.yaml'
])
.it('should be able to refence messages into components', (ctx, done) => {
expect(ctx.stdout).to.contain('Check out your shiny new bundled files at ./test/integration/bundle/final.yaml\n');
fileCleanup('./test/integration/bundle/final.yaml');
done();
});

test
.stdout()
.command([
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--reference-into-components', '--output=test/integration/bundle/final.yaml'
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--output=test/integration/bundle/final.yaml'
])
.it('should be able to bundle multiple specs along with custom reference', (ctx, done) => {
expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n');
Expand All @@ -75,7 +64,7 @@ describe('bundle', () => {
test
.stdout()
.command([
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--reference-into-components', '--output=test/integration/bundle/final.yaml', '--base=./test/integration/bundle/first-asyncapi.yaml'
'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--output=test/integration/bundle/final.yaml', '--base=./test/integration/bundle/first-asyncapi.yaml'
])
.it('should be able to bundle correctly with overwriting base file', (ctx, done) => {
expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n');
Expand Down
3 changes: 3 additions & 0 deletions test/integration/bundle/channels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channels:
commentLikedChannel:
address: comment/liked
5 changes: 2 additions & 3 deletions test/integration/bundle/feature.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
asyncapi: "2.5.0"
asyncapi: "2.6.0"
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user logouts
channels:
user/loggedOut:
subcribe:
unsubcribe:
message:
$ref: 'test/integration/bundle/messages.yaml#/messages/UserLoggedOut'

5 changes: 2 additions & 3 deletions test/integration/bundle/final-asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.5.0
asyncapi: 2.6.0
info:
title: Account Service
version: 1.0.0
Expand All @@ -9,7 +9,7 @@ channels:
message:
$ref: '#/components/messages/UserSignedUp'
user/loggedOut:
subcribe:
unsubcribe:
message:
$ref: '#/components/messages/UserLoggedOut'
components:
Expand Down Expand Up @@ -38,4 +38,3 @@ components:
timestamp:
type: number
descriptio: Time stamp when the user logged out

2 changes: 1 addition & 1 deletion test/integration/bundle/first-asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: "2.5.0"
asyncapi: "2.6.0"
info:
title: Account Service
version: 1.0.0
Expand Down
34 changes: 4 additions & 30 deletions test/integration/bundle/first-asyncapiv3.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
asyncapi: 3.0.0
info:
title: Account Service
title: Example Service
version: 1.0.0
description: This service is in charge of processing user signupsA
description: Example Service.
channels:
userSignedup:
address: 'user/signedup'
messages:
userSignedUpMessage:
$ref: './test/integration/bundle/messages.yaml#/messages/UserSignedUp'
test:
address: '/test'
messages:
testMessage:
$ref: '#/components/messages/TestMessage'
operations:
UserSignedUp:
action: send
channel:
$ref: '#/channels/userSignedup'
messages:
- $ref: './test/integration/bundle/messages.yaml#/messages/UserSignedUp'
TestOpp:
action: send
channel:
$ref: '#/channels/test'
messages:
- $ref: '#/components/messages/TestMessage'
components:
messages:
TestMessage:
payload:
type: string
commentLikedChannel:
$ref: './test/integration/bundle/channels.yaml#/channels/commentLikedChannel'
Loading