Generates code from AsyncAPI documents using AsyncAPI Generator templates.
The asyncapi generate command generates code from AsyncAPI documents using AsyncAPI Generator templates. This allows developers to quickly implement API clients, servers, documentation, and more based on their AsyncAPI specifications.
The command supports three main subcommands:
- Generate from template:
asyncapi generate fromTemplate <asyncapi-spec> <template> - Generate models:
asyncapi generate models <asyncapi-spec> - Generate client:
asyncapi generate client <language> <asyncapi-spec>
--output, -o <directory>: Specify the output directory for generated code--install: Install the template and its dependencies--force-write: Force writing of generated files even if the output directory is not empty--param, -p <key=value>: Additional parameters to pass to the template--map-base-url: Maps all schema references from base URL to local folder--registry-url: Specifies the URL of the private registry for fetching templates--registry-auth: The registry username and password encoded with base64--registry-token: The npm registry authentication token--no-interactive: Disable interactive mode and run with provided flags--debug: Enable more specific errors in the console
| Flag | Description |
|---|---|
--output, -o |
Directory where generated code will be saved |
--install |
Install the template and its dependencies |
--force-write |
Force writing of generated files |
--param, -p |
Additional parameters to pass to the template |
--map-base-url |
Maps all schema references from base URL to local folder |
--registry-url |
Specifies the URL of the private registry |
--registry-auth |
The registry username and password encoded with base64 |
--registry-token |
The npm registry authentication token |
--no-interactive |
Disable interactive mode |
--debug |
Enable more specific errors |
-
Generate models from AsyncAPI specification:
asyncapi generate models spec.yaml
-
Generate client for a specific language:
asyncapi generate client javascript spec.yaml --param version=1.0.0 --output ./client
-
Generate code from template with specific parameters:
asyncapi generate fromTemplate spec.yaml @asyncapi/html-template --param version=1.0.0 --output ./docs
-
Generate code with force-write option:
asyncapi generate fromTemplate spec.yaml @asyncapi/html-template --force-write --output ./generated
-
Generate code with registry configuration:
asyncapi generate fromTemplate spec.yaml @asyncapi/html-template --registry-url https://custom-registry.com --registry-token mytoken