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.
-
Hooks: Hooks are designed to let template developers hook into the template generation process. For example, one can create a hook code that will be automatically invoked right after the template generation process has ended.
-
React-sdk: AsyncAPI React SDK is a set of components/functions to use React as render engine for the generator. This is the library that undestand components from Generator's templates that are configured to use
reactrender engine. -
Generator-helpers: A utility library that provides helper functions and utilities to simplify template development. It reduces boilerplate and speeds up template creation.
-
Generator-components: A library of reusable components that can be shared across different templates, helping to avoid duplication and accelerate template development.
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
[!IMPORTANT] Experimental Feature: AsyncAPI Generator also comes with baked-in templates - official templates shipped directly inside the Generator (
@asyncapi/generator). They cover code, docs, configs, and SDKs, and are maintained under /packages/templates directory, following a strict, opinionated structure for consistency and ease of maintenance. This feature is not recommended for production use. For those who want to try them out or learn more, see the Baked-in templates documentation.
Hooks
Hooks are functions called by the generator at specific moments in the generation process. Hooks can be anonymous functions, but you can also assign them function names. These hooks can have arguments provided to them, or they may be expected to return a value.
These hooks are included in the generator without adding any specific dependency to the library. You still have to enable the given hook in the configuration explicitly because some hooks can execute automatically without passing a specific parameter. Learn more about configuration and what hooks are available out of the box.
Contributing
For the development setup, you can follow the detailed guide in Developement guide
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