
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
@asyncapi/converter
Advanced tools
Convert AsyncAPI documents older to newer versions and you can also convert OpenAPI documents to AsyncAPI documents.
npm i @asyncapi/converter
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:
...
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);
}
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)
}
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:
The input must be valid AsyncAPI document.
External references are not resolved and converted, they remain untouched, even if they are incorrect.
In version 3.0.0, the channel identifier is no longer its address, but due to the difficulty of defining a unique identifier, we still treat the address as an identifier. If there is a need to assign an identifier other than an address, an x-channelId extension should be defined at the level of the given channel.
# 2.x.x
channels:
users/signup:
x-channelId: 'userSignUp'
...
users/logout:
...
# 3.0.0
channels:
userSignUp:
...
users/logout:
...
The publish operation is treated as a receive action, and subscribe is treated as a send action. Conversion by default is embraced from the application perspective. If you want to change this logic, you need to specify v2tov3.pointOfView configuration as client.
If the operation does not have an operationId field defined, the unique identifier of the operation will be defined as a combination of the identifier of the channel on which the operation was defined + the type of operation, publish or subscribe. Identical situation is with messages. However, here the priority is the messageId field and then the concatenation {publish|subscribe}.messages.{optional index of oneOf messages}.
# 2.x.x
channels:
users/signup:
publish:
message:
...
subscribe:
operationId: 'userSignUpEvent'
message:
oneOf:
- messageId: 'userSignUpEventMessage'
...
- ...
# 3.0.0
channels:
users/signup:
messages:
publish.message:
...
userSignUpEventMessage:
...
userSignUpEvent.message.1:
...
operations:
users/signup.publish:
action: receive
...
userSignUpEvent:
action: send
...
Security requirements that use scopes are defined in the appropriate places inline, the rest as a reference to the components.securitySchemes objects.
If servers are defined at the channel level, they are converted as references to the corresponding objects defined in the servers field.
Channels and servers defined in components are also converted (unless configured otherwise).
stream instead of topics or events) are converted correctly but information about framing type and delimiter is missing until a protocolInfo for that purpose is created.parameter.schema is defined with a reference, it will NOT look into the schema reference and include any relevant keywords for the v3 parameter. It will just create an empty parameter but leave the schema in the components section as is.
# 2.x.x
channels:
"{myParameter}":
parameters:
myParameter:
schema:
$ref: "#/components/schemas/mySchema"
components:
schemas:
mySchema:
enum: ["test"]
default: "test"
examples: ["test"]
# 3.0.0
channels:
"{myParameter}":
parameters:
myParameter: {}
components:
schemas:
mySchema:
enum: ["test"]
default: "test"
examples: ["test"]
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'.
With server perspective: action becomes receive
With client perspective: action becomes send
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'.
With server perspective: action becomes receive
With client perspective: action becomes send
npm installnpm testRead CONTRIBUTING guide.
Thanks goes to these wonderful people (emoji key):
Maciej Urbańczyk 🚧 💻 🐛 👀 ⚠️ 📖 | Fran Méndez 🚧 💻 🐛 👀 ⚠️ 📖 | Lukasz Gornicki 🚧 💻 🐛 👀 ⚠️ 📖 🚇 | Germán Schnyder 💻 ⚠️ | Barbara Czyż 🚇 | depimomo 💻 | Orville Daley 💻 |
Ryan R Sundberg 💻 | Mohan Kumar 💻 ⚠️ 📖 💡 | Mintu Gogoi 💻 📖 💡 ⚠️ |
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
Convert AsyncAPI documents from older to newer versions.
The npm package @asyncapi/converter receives a total of 40,254 weekly downloads. As such, @asyncapi/converter popularity was classified as popular.
We found that @asyncapi/converter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.