Skip to content

Latest commit

 

History

History
137 lines (104 loc) · 3.67 KB

API.md

File metadata and controls

137 lines (104 loc) · 3.67 KB

Classes

Document

Members

resolveboolean

Functions

bundle(files, [options])Document

Document

Kind: global class

new Document(parsedJSONList, base)

Param Type
parsedJSONList Array.<Object>
base Object

Example

const document = new Document(parsedJSONList, base);

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

resolve ⇒ boolean

Kind: global variable

Param Type
asyncapiDocument AsyncAPIObject

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));