Package Exports
- @asyncapi/bundler
- @asyncapi/bundler/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@asyncapi/bundler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Overview
An official library that lets you bundle/merge your specification files into one. AsyncAPI bundler can help you if -
your specification file is divided into different smaller files and is using json `$ref` to reference components
# asyncapi.yaml
asyncapi: '2.2.0'
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signups
channels:
user/signup:
subscribe:
message:
$ref: './messages.yaml#/messages/UserSignedUp'
#messages.yaml
messages:
UserSignedUp:
payload:
type: object
properties:
displayName:
type: string
description: Name of the user
email:
type: string
format: email
description: Email of the user
# After combining
asyncapi: 2.2.0
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signups
channels:
user/signedup:
subscribe:
message:
payload:
type: object
properties:
displayName:
type: string
description: Name of the user
email:
type: string
format: email
description: Email of the user
you have different standalone specification files that define a larger system, see examples here
# signup.yaml
asyncapi: '2.2.0'
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user Signup
channels:
user/signedup:
subscribe:
message:
payload:
type: object
properties:
displayName:
type: string
email:
type: string
format: email
# login.yaml
asyncapi: '2.2.0'
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signup
channels:
user/loggenin:
subscribe:
message:
payload:
type: object
properties:
displayName:
type: string
# After combining
# asyncapi.yaml
asyncapi: '2.2.0'
info:
title: Account Service
version: 1.0.0
description: This service is in charge for processing user authentication
channles:
user/signedup:
subscribe:
message:
payload:
type: object
properties:
displayName:
type: string
email:
type: string
format: email
user/loggedin:
subscribe:
message:
payload:
type: object
properties:
displayName:
type: stringInstallation
npm install @asyncapi/bundlerUsage
AsyncAPI-bundler could be easily used within your javascript projects as a Nodejs module.
const bundler = require('@asyncapi/bundler');
const fs = require('fs');
const path = require('path');
const filePaths = ['./camera.yml','./audio.yml']
const document = await bundler.bundle(
filePaths.map(filePath => fs.readFileSync(path.resolve(filePaths), 'utf-8')),
{
base: fs.readFileSync(path.resolve('./base.yml'), 'utf-8')
}
);
console.log(document.json()); // the complete bundled asyncapi document.bundle(files, options)
Kind: global function
| Param | Type | Description |
|---|---|---|
| files | Array.<string> | Array.<Object> |
files that are to be bundled |
| options | Object |
|
| options.base | string | object |
base object whose prperties will be retained. |
| options.parser | Object |
asyncapi parser object |
| options.validate | boolean |
pass false to not validate file before merge |
