Skip to content

Latest commit

 

History

History
117 lines (89 loc) · 3.3 KB

API.md

File metadata and controls

117 lines (89 loc) · 3.3 KB

Classes

Document

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

bundle(files, [options]) ⇒ Document

Kind: global function

Param Type Description
files Array.<string>

Array of stringified AsyncAPI documents in YAML format, that are to be bundled (or array of filepaths, resolved and passed via Array.map() and fs.readFileSync, which is the same, see README.md).

[options] Object
[options.base] string | object

Base object whose properties will be retained.

[options.referenceIntoComponents] boolean

Pass true to resolve external references to components.

Example
TypeScript

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

async function main() {
  const document = await bundle([readFileSync('./main.yaml', 'utf-8')], {
    referenceIntoComponents: 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 { readFileSync, writeFileSync } = require('fs');
const bundle = require('@asyncapi/bundler');

async function main() {
  const document = await bundle([readFileSync('./main.yaml', 'utf-8')], {
    referenceIntoComponents: true,
  });
  writeFileSync('asyncapi.yaml', document.yml());
}

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

JavaScript ESM module system

'use strict';

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

async function main() {
  const document = await bundle([readFileSync('./main.yaml', 'utf-8')], {
    referenceIntoComponents: true,
  });
  writeFileSync('asyncapi.yaml', document.yml());
}

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