Home

Awesome

AsyncAPI Converter

Convert AsyncAPI documents older to newer versions and you can also convert OpenAPI documents to AsyncAPI documents.

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

All Contributors

<!-- ALL-CONTRIBUTORS-BADGE:END --> <!-- toc is generated with GitHub Actions do not remove toc markers --> <!-- toc --> <!-- tocstop -->

Installation

npm i @asyncapi/converter

Usage

From CLI

To convert an AsyncAPI document in the console needs the official AsyncAPI CLI.

If you don't have CLI installed, run this command to install the CLI globally on your system:

npm install -g @asyncapi/cli

Minimal usage example with output given:

asyncapi convert streetlights.yml -o streetlights2.yml

# Result:
asyncapi: '2.0.0'
channels:
...

Convert to a specific version:

asyncapi convert streetlights.yml -o streetlights2.yml -t 2.3.0

# Result:
asyncapi: '2.3.0'
channels:
...

In JS

const fs = require('fs');
const { convert } = require('@asyncapi/converter')

try {
  const asyncapi = fs.readFileSync('streetlights.yml', 'utf-8')
  console.log(convert(asyncapi, '2.6.0'));
} catch (e) {
  console.error(e);
}

In TS

import { convert } from '@asyncapi/converter';
import type { ConvertVersion, ConvertOptions } from '@asyncapi/converter';

try {
  const toVersion: ConvertVersion = '2.6.0';
  const asyncapi = fs.readFileSync('streetlights.yml', 'utf-8')
  console.log(convert(asyncapi, toVersion));
} catch (e) {
  console.error(e)
}

Conversion 2.x.x to 3.x.x

NOTE: This feature is still WIP, and is until the final release of 3.0.0.

Conversion to version 3.x.x from 2.x.x has several assumptions that should be known before converting:

Known missing features

OpenAPI 3.0 to AsyncAPI 3.0 Conversion

The converter now supports transformation from OpenAPI 3.0 to AsyncAPI 3.0. This feature enables easy transition of existing OpenAPI 3.0 documents to AsyncAPI 3.0.

To use this new conversion feature:

const fs = require('fs');
const { convertOpenAPI } = require('@asyncapi/converter')

try {
  const openapi = fs.readFileSync('openapi.yml', 'utf-8')
  const asyncapi = convertOpenAPI(openapi, '3.0.0', { from: 'openapi' });
  console.log(asyncapi);
} catch (e) {
  console.error(e);
}

When converting from OpenAPI to AsyncAPI you can now specify the perspective of the conversion using the perspective option. This allows you to choose whether the conversion should be from an application or client point of view

const { convertOpenAPI } = require('@asyncapi/converter')

try {
  const asyncapi2 = fs.readFileSync('asyncapi2.yml', 'utf-8')
  const asyncapi3 = convertOpenAPI(asyncapi2, '3.0.0', { openAPIToAsyncAPI: { perspective: 'client' } });
  console.log(asyncapi3);
} catch (e) {
  console.error(e);
}

The perspective option can be set to either 'server' (default) or 'client'.

Limitations

Postman Collection to AsyncAPI conversion

The converter now also supports conversion from postman collection to AsyncAPI 3.0. This feature enables easy transition of existing postman collection to any AsyncAPI 3.0 documents.

To use this new conversion feature:

const fs = require('fs');
const { convertPostman } = require('@asyncapi/converter')
try {
  const postman = fs.readFileSync('postman-collection.yml', 'utf-8')
  const asyncapi = convertPostman(postman, '3.0.0');
  console.log(asyncapi);
} catch (e) {
  console.error(e);
}

When converting from postman collection to AsyncAPI you can now specify the perspective of the conversion using the perspective option. This allows you to choose whether the conversion should be from an application or client point of view

const { convertPostman } = require('@asyncapi/converter')
try {
  const postman = fs.readFileSync('postman-collection.yml', 'utf-8')
  const asyncapi = convertPostman(postman, '3.0.0', { perspective: 'client' });
  console.log(asyncapi);
} catch (e) {
  console.error(e);
}

The perspective option can be set to either 'server' (default) or 'client'.

Limitations

Development

  1. Setup project by installing dependencies npm install
  2. Write code and tests.
  3. Make sure all tests pass npm test

Contribution

Read CONTRIBUTING guide.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/magicmatatjahu"><img src="https://avatars.githubusercontent.com/u/20404945?v=4?s=100" width="100px;" alt="Maciej Urbańczyk"/><br /><sub><b>Maciej Urbańczyk</b></sub></a><br /><a href="#maintenance-magicmatatjahu" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Amagicmatatjahu" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Amagicmatatjahu" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Documentation">📖</a></td> <td align="center" valign="top" width="14.28%"><a href="http://www.fmvilas.com/"><img src="https://avatars.githubusercontent.com/u/242119?v=4?s=100" width="100px;" alt="Fran Méndez"/><br /><sub><b>Fran Méndez</b></sub></a><br /><a href="#maintenance-fmvilas" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Afmvilas" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Afmvilas" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Documentation">📖</a></td> <td align="center" valign="top" width="14.28%"><a href="https://www.brainfart.dev/"><img src="https://avatars.githubusercontent.com/u/6995927?v=4?s=100" width="100px;" alt="Lukasz Gornicki"/><br /><sub><b>Lukasz Gornicki</b></sub></a><br /><a href="#maintenance-derberg" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Aderberg" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Aderberg" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Documentation">📖</a> <a href="#infra-derberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/germanschnyder"><img src="https://avatars.githubusercontent.com/u/1844525?v=4?s=100" width="100px;" alt="Germán Schnyder"/><br /><sub><b>Germán Schnyder</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=germanschnyder" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/commits?author=germanschnyder" title="Tests">⚠️</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/bszwarc"><img src="https://avatars.githubusercontent.com/u/17266942?v=4?s=100" width="100px;" alt="Barbara Czyż"/><br /><sub><b>Barbara Czyż</b></sub></a><br /><a href="#infra-bszwarc" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/depimomo"><img src="https://avatars.githubusercontent.com/u/12368942?v=4?s=100" width="100px;" alt="depimomo"/><br /><sub><b>depimomo</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=depimomo" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/crypto-cmd"><img src="https://avatars.githubusercontent.com/u/54287503?v=4?s=100" width="100px;" alt="Orville Daley"/><br /><sub><b>Orville Daley</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=crypto-cmd" title="Code">💻</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="https://www.arctype.co/"><img src="https://avatars.githubusercontent.com/u/549273?v=4?s=100" width="100px;" alt="Ryan R Sundberg"/><br /><sub><b>Ryan R Sundberg</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=sundbry" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/ItshMoh"><img src="https://avatars.githubusercontent.com/u/121867882?v=4?s=100" width="100px;" alt="Mohan Kumar"/><br /><sub><b>Mohan Kumar</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=ItshMoh" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/commits?author=ItshMoh" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=ItshMoh" title="Documentation">📖</a> <a href="#example-ItshMoh" title="Examples">💡</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/Gmin2"><img src="https://avatars.githubusercontent.com/u/127925465?v=4?s=100" width="100px;" alt="Mintu Gogoi"/><br /><sub><b>Mintu Gogoi</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=Gmin2" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/commits?author=Gmin2" title="Documentation">📖</a> <a href="#example-Gmin2" title="Examples">💡</a> <a href="https://github.com/asyncapi/converter-js/commits?author=Gmin2" title="Tests">⚠️</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!