generator
Use your AsyncAPI definition to generate literally anything. Markdown documentation, Node.js code, HTML documentation, anything!
Top Related Projects
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
GUI / visual editor for creating and editing OpenAPI / Swagger definitions
Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Quick Overview
AsyncAPI Generator is a powerful tool designed to generate documentation, code, and other assets from AsyncAPI documents. It supports multiple templates and can be used as a CLI tool or integrated into other projects as a library. The generator is highly extensible, allowing users to create custom templates for various programming languages and frameworks.
Pros
- Supports multiple programming languages and frameworks through templates
- Highly customizable and extensible
- Can be used as both a CLI tool and a library
- Active community and regular updates
Cons
- Learning curve for creating custom templates
- Limited built-in templates compared to some other API documentation tools
- May require additional setup for complex use cases
- Performance can be slower for large AsyncAPI documents
Code Examples
- Generate documentation using the CLI:
asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template -o ./output
This command generates HTML documentation from an AsyncAPI document using the official HTML template.
- Using the generator as a library in Node.js:
const generator = require('@asyncapi/generator');
const options = {
templateName: '@asyncapi/html-template',
output: './output',
forceWrite: true,
};
generator.generate('asyncapi.yaml', options)
.then(() => console.log('Done!'))
.catch(console.error);
This example demonstrates how to use the generator as a library to generate documentation programmatically.
- Creating a custom template:
module.exports = {
generate: async ({ asyncapi, templateParams, templateConfig }) => {
// Custom generation logic here
return {
'output.txt': `Generated content for ${asyncapi.info.title}`
};
},
templateConfig: {
supportedProtocols: ['mqtt', 'kafka'],
parameters: {
// Template-specific parameters
}
}
};
This code snippet shows the basic structure of a custom template for the AsyncAPI Generator.
Getting Started
To get started with AsyncAPI Generator:
-
Install the generator globally:
npm install -g @asyncapi/generator -
Create an AsyncAPI document (e.g.,
asyncapi.yaml) -
Generate documentation using a template:
asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template -o ./output -
View the generated output in the
./outputdirectory
For more advanced usage, refer to the official documentation on the AsyncAPI Generator GitHub repository.
Competitor Comparisons
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
Pros of spec
- Focuses on defining the AsyncAPI specification, providing a standardized format for describing asynchronous APIs
- Serves as the authoritative source for the AsyncAPI specification, ensuring consistency across implementations
- Lighter weight and more focused in scope compared to generator
Cons of spec
- Lacks code generation capabilities, which generator provides
- Does not include tooling for working with AsyncAPI documents, unlike generator which offers various utilities
Code Comparison
spec:
asyncapi: 2.5.0
info:
title: Example API
version: 1.0.0
channels:
user/signedup:
publish:
message:
$ref: '#/components/messages/UserSignedUp'
generator:
const generator = new Generator('@asyncapi/html-template', {
output: './output',
templateParams: {
singleFile: true
}
});
await generator.generateFromFile('./asyncapi.yaml');
The spec repository focuses on defining the AsyncAPI specification structure, while generator provides tools for working with and generating code from AsyncAPI documents. spec is essential for standardization, while generator offers practical implementation and documentation generation capabilities.
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
Pros of spec
- Focuses on defining the AsyncAPI specification, providing a standardized format for describing asynchronous APIs
- Serves as the authoritative source for the AsyncAPI specification, ensuring consistency across implementations
- Lighter weight and more focused in scope compared to generator
Cons of spec
- Lacks code generation capabilities, which generator provides
- Does not include tooling for working with AsyncAPI documents, unlike generator which offers various utilities
Code Comparison
spec:
asyncapi: 2.5.0
info:
title: Example API
version: 1.0.0
channels:
user/signedup:
publish:
message:
$ref: '#/components/messages/UserSignedUp'
generator:
const generator = new Generator('@asyncapi/html-template', {
output: './output',
templateParams: {
singleFile: true
}
});
await generator.generateFromFile('./asyncapi.yaml');
The spec repository focuses on defining the AsyncAPI specification structure, while generator provides tools for working with and generating code from AsyncAPI documents. spec is essential for standardization, while generator offers practical implementation and documentation generation capabilities.
GUI / visual editor for creating and editing OpenAPI / Swagger definitions
Pros of openapi-gui
- User-friendly graphical interface for creating and editing OpenAPI specifications
- Real-time preview of the generated OpenAPI document
- Supports importing existing OpenAPI specifications for editing
Cons of openapi-gui
- Limited to OpenAPI specifications, while generator supports AsyncAPI
- Less extensive code generation capabilities compared to generator
- May require more manual input for complex API structures
Code Comparison
openapi-gui (HTML/JavaScript):
<div id="swagger-editor"></div>
<script src="https://unpkg.com/swagger-editor-dist/swagger-editor-bundle.js"></script>
<script>
SwaggerEditorBundle.SwaggerEditor({ dom_id: '#swagger-editor' });
</script>
generator (JavaScript):
const generator = require('@asyncapi/generator');
const template = require('@asyncapi/html-template');
generator.generate(asyncapiDocument, template, {
outputDir: './output'
}).then(() => console.log('Done!'));
While openapi-gui focuses on providing a visual interface for creating OpenAPI specifications, generator is more versatile, supporting AsyncAPI and offering extensive code generation capabilities. openapi-gui is better suited for users who prefer a graphical approach to API design, while generator caters to developers who need powerful code generation tools and support for AsyncAPI specifications.
Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
Pros of Prism
- Supports multiple API specification formats (OpenAPI, Postman Collections)
- Offers mock server functionality for API testing
- Provides a CLI tool for easy integration into workflows
Cons of Prism
- Focused primarily on HTTP APIs, less suitable for event-driven architectures
- Limited template customization options compared to Generator
- Lacks extensive code generation capabilities
Code Comparison
Generator:
const generator = new AsyncAPIGenerator();
await generator.generateFromFile('asyncapi.yaml', './output');
Prism:
const { Prism } = require('@stoplight/prism-core');
const { createServer } = require('@stoplight/prism-http-server');
const prism = new Prism({ specification: './openapi.yaml' });
createServer(prism, { port: 4010 });
Generator focuses on generating code and documentation from AsyncAPI specifications, while Prism primarily serves as a mock server and validator for OpenAPI specifications. Generator offers more flexibility in terms of output customization and supports a wider range of use cases for event-driven architectures. Prism, on the other hand, excels in API mocking and testing scenarios, making it a valuable tool for API development and integration testing.
swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
Pros of Swagger Codegen
- Mature project with extensive language support
- Large community and ecosystem
- Supports both client and server code generation
Cons of Swagger Codegen
- Primarily focused on REST APIs, limited support for other protocols
- Can be complex to customize and extend
- Slower development cycle and release process
Code Comparison
Swagger Codegen (Java):
public class PetApi {
private final ApiClient apiClient;
public PetApi() {
this(Configuration.getDefaultApiClient());
}
}
AsyncAPI Generator (JavaScript):
const generator = new Generator('@asyncapi/html-template', {
output: './output',
params: {
singleFile: true
}
});
Key Differences
- AsyncAPI Generator focuses on event-driven architectures and async APIs
- Swagger Codegen primarily targets REST APIs
- AsyncAPI Generator offers a more modern, modular approach
- Swagger Codegen provides broader language support
- AsyncAPI Generator has a faster development cycle and more frequent releases
Both tools serve different purposes and can be complementary in API development workflows. AsyncAPI Generator is better suited for modern, event-driven architectures, while Swagger Codegen excels in traditional REST API scenarios with its extensive language support and mature ecosystem.
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Pros of openapi-generator
- Supports a wider range of programming languages and frameworks
- More extensive documentation and community support
- Offers more customization options for generated code
Cons of openapi-generator
- Steeper learning curve due to its complexity
- Can be slower to generate code for large specifications
- May produce more verbose output compared to asyncapi-generator
Code Comparison
generator (AsyncAPI):
const generator = new Generator('@asyncapi/html-template', '/path/to/asyncapi.yaml');
await generator.generate('/output/directory');
openapi-generator:
openapi-generator generate -i /path/to/openapi.yaml -g javascript -o /output/directory
Key Differences
- generator focuses on AsyncAPI specifications, while openapi-generator is designed for OpenAPI (formerly Swagger) specifications
- generator is primarily JavaScript-based, whereas openapi-generator is implemented in Java
- openapi-generator offers a wider range of output formats and languages, but generator provides more specialized support for event-driven architectures
Both tools serve different purposes within the API ecosystem, with generator being more focused on asynchronous APIs and openapi-generator offering broader support for RESTful APIs across multiple languages and frameworks.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
This is a Monorepo managed using Turborepo and contains the following package:
-
Generator: This is a tool that you can use to generate whatever you want basing on the AsyncAPI specification file as an input.
-
Nunjucks-filters: This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies seprately.
warning: This package doesn't support AsyncAPI 1.x anymore. We recommend to upgrade to the latest AsyncAPI version using the AsyncAPI converter (You can refer to installation guide). If you need to convert documents on the fly, you may use the Node.js or Go converters.
Overview
Generator is a tool that you can use to generate whatever you want basing on the AsyncAPI specification file as an input. For more information read the docs.
There is a large number of templates that are ready to use and are officially supported by the AsyncAPI Initiative.
List of official generator templates
| Template Name | Description | Source code |
|---|---|---|
@asyncapi/nodejs-template | Generates Nodejs service that uses Hermes package | click here |
@asyncapi/nodejs-ws-template | Generates Nodejs service that supports WebSockets protocol only | click here |
@asyncapi/java-template | Generates Java JMS application | click here |
@asyncapi/java-spring-template | Generates Java Spring service | click here |
@asyncapi/java-spring-cloud-stream-template | Generates Java Spring Cloud Stream service | click here |
@asyncapi/python-paho-template | Generates Python service that uses Paho library | click here |
@asyncapi/html-template | Generates HTML documentation site | click here |
@asyncapi/markdown-template | Generates documentation in Markdown file | click here |
@asyncapi/ts-nats-template | Generates TypeScript NATS client | click here |
@asyncapi/go-watermill-template | Generates Go client using Watermill | click here |
@asyncapi/dotnet-nats-template | Generates .NET C# client using NATS | click here |
@asyncapi/php-template | Generates PHP client using RabbitMQ | click here |
@asyncapi/dotnet-rabbitmq-template | Generates .NET C# client using RabbitMQ | click here |
You can find above templates and the ones provided by the community in this list
Generator Filters
This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies seprately.
This library consists of:
- Custom filters. Check out API docs for complete list
- Lodash-powered filters. For the list of all available filters check official docs
Release Process
To release a major/minor/patch:
Conventional Commits:
To maintain a clear git history of commits and easily identify what each commit changed and whether it triggered a release, we use conventional commits. The feat and fix prefixes are particularly important as they are needed to trigger changesets. Using these prefixes ensures that the changes are correctly categorized and the versioning system functions as expected.
For Example:
feat: add new feature
Manual
-
Create a new release markdown file in the
.changesetdirectory. The filename should indicate what the change is about. -
Add the following content to the file in this particular format:
--- "@package-name-1": [type] (major/minor/patch) "@package-name-2": [type] --- [Provide a brief description of the changes. For example: Added a new Release GitHub Flow to the Turborepo. No new features or bugfixes were introduced.]For Example:
--- "@asyncapi/generator": minor --- Adding new Release Github Flow to the Turborepo. No new features or bugfixes were introduced. -
Include the file in your pull request.
Using CLI
-
Create a new release markdown file using changeset CLI. Below command will trigger an interactive prompt that you can use to specify release type and affected packages.
npx -p @changesets/cli@2.27.7 changeset -
Include the file in your pull request.
[!TIP] For more detailed instructions, you can refer to the official documentation for creating a changeset: Adding a changeset
Release Flow:
-
Add a Changeset:
- When you make changes that need to be released, create a markdown file in the
.changesetdirectory stating the package name and level of change (major/minor/patch).
- When you make changes that need to be released, create a markdown file in the
-
Open a Pull Request:
- Push your changes and open a Pull Request (PR). After the PR is merged the changeset file helps communicate the type of changes (major, minor, patch).
-
CI Processes Changeset:
-
After PR is merged, a dedicated GitHub Actions release workflow runs using changeset action,
-
This action reads the markdown files in the
.changesetfolder and creates a PR with the updated version of the package and removes the markdown file. For example:Before:
"name": "@asyncapi/generator", "version": "2.0.1",After:
"name": "@asyncapi/generator", "version": "3.0.1", -
The new PR will also contain the description from the markdown files,
-
AsyncAPI bot automatically merge such release PR.
-
-
Release the Package:
- After the PR is merged, the CI/CD pipeline triggers again. The
changesets/actionstep identifies that the PR was created by itself. It then verifies if the current version of the package is greater than the previously released version. If a difference is detected, it executes the publish command to release the updated package.
- After the PR is merged, the CI/CD pipeline triggers again. The
Contributing
Read CONTRIBUTING guide.
Contributors â¨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Top Related Projects
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
GUI / visual editor for creating and editing OpenAPI / Swagger definitions
Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot