Skip to content

Latest commit

 

History

History
120 lines (92 loc) · 3.35 KB

API.md

File metadata and controls

120 lines (92 loc) · 3.35 KB

Classes

Document

Functions

bundle(files, [options])Document

Document

Kind: global class

new Document(AsyncAPIObject)

Param Type
AsyncAPIObject Object

Example

const document = new Document(bundledDocument);

console.log(document.json()); // get JSON object
console.log(document.yml()); // get YAML string
console.log(document.string()); // get JSON string

document.json() ⇒ Object

Kind: instance method of Document

document.yml() ⇒ string

Kind: instance method of Document

document.string() ⇒ string

Kind: instance method of Document

bundle(files, [options]) ⇒ Document

Kind: global function

Param Type Description
files string | Array.<string>

One or more relative/absolute paths to AsyncAPI Documents that should be bundled.

[options] Object
[options.base] string

One relative/absolute path to base object whose properties will be retained.

[options.baseDir] string

One relative/absolute path to directory relative to which paths to AsyncAPI Documents that should be bundled will be resolved.

[options.xOrigin] boolean

Pass true to generate properties x-origin that will contain historical values of dereferenced $refs.

Example
TypeScript

import { writeFileSync } from 'fs';
import bundle from '@asyncapi/bundler';

async function main() {
 const document = await bundle(['social-media/comments-service/main.yaml'], {
   baseDir: 'example-data',
   xOrigin: true,
 });

 console.log(document.yml()); // the complete bundled AsyncAPI document
 writeFileSync('asyncapi.yaml', document.yml());  // the complete bundled AsyncAPI document
}

main().catch(e => console.error(e));

JavaScript CJS module system

'use strict';

const { writeFileSync } = require('fs');
const bundle = require('@asyncapi/bundler');

async function main() {
 const document = await bundle(['social-media/comments-service/main.yaml'], {
   baseDir: 'example-data',
   xOrigin: true,
 });
 writeFileSync('asyncapi.yaml', document.yml());
}

main().catch(e => console.error(e));

JavaScript ESM module system

'use strict';

import { writeFileSync } from 'fs';
import bundle from '@asyncapi/bundler';

async function main() {
 const document = await bundle(['social-media/comments-service/main.yaml'], {
   baseDir: 'example-data',
   xOrigin: true,
 });
 writeFileSync('asyncapi.yaml', document.yml());
}

main().catch(e => console.error(e));