AsyncAPI Conference

London Edition

22nd - 24th of September, 2025 | London, UK

34 days until the end of Call for Speakers

Configuration file

Found an error? Have a suggestion?Edit this page on GitHub

You can configure your AsyncAPI Generator template using either a dedicated .ageneratorrc YAML file or through the generator property in your package.json file. Previously, generator configuration had to be defined in the package.json file. Now, you can define the configuration in a separate .ageneratorrc file. The configuration defined in the .ageneratorrc file will override any configuration defined in package.json. The generator will first check for the .ageneratorrc file in the template's root directory, and if not found, it will look for the generator config in package.json.

Configuration Methods

Create a .ageneratorrc file in the root of your template with YAML syntax. This approach keeps your template configuration separate from package metadata:

1renderer: react
2apiVersion: v3
3supportedProtocols:
4  - amqp
5  - mqtt
6
7parameters:
8  server:
9    description: The server you want to use in the code.
10    required: true
11  dummyParameter:
12    description: Example of parameter with default value.
13    default: just a string
14    required: false
15
16conditionalFiles:
17  path/to/file/that/is/relative/to/template/dir/test-amqp.js:
18    subject: server.protocol
19    validation:
20      const: amqp
21  path/to/file/that/is/relative/to/template/dir/support.html:
22    subject: info.contact
23    validation:
24      required:
25        - url
26
27conditionalGeneration:
28  conditionalOnFile.js:
29    parameter: singleFile
30    validation:
31      not:
32        const: true
33  conditionOnFolderInfo:
34    subject: info.contact.name
35    validation:
36      const: API Support
37
38nonRenderableFiles:
39  - src/api/middlewares/*.*
40  - lib/lib/config.js
41
42generator: "<2.0.0"
43
44filters:
45  - my-package-with-filters
46
47hooks:
48  '@asyncapi/generator-hooks': hookFunctionName
49  my-custom-hooks-package:
50    - myHook
51    - andAnotherOne
52

Option 2: Using package.json

Alternatively, you can include your configuration in the generator property of your package.json file:

1"generator": {
2  "renderer": "react",
3  "apiVersion": "v3",
4  "supportedProtocols": ["amqp", "mqtt"],
5  "parameters": {
6    "server": {
7      "description": "The server you want to use in the code.",
8      "required": true
9    },
10    "dummyParameter": {
11      "description": "Example of parameter with default value.",
12      "default": "just a string",
13      "required": false
14    }
15  },
16  "conditionalGeneration": {
17     "conditionalOnFile.js": { 
18       "parameter": "singleFile", 
19       "validation": {
20          "not": { "const": "true" } 
21      }
22    },
23     "conditionOnFolder": {
24       "parameter": "singleFolder", 
25       "validation": {
26          "not": { "const": "true" } 
27      }
28    },
29     "conditionOnFolderInfo": {
30       "subject": "info.contact.name",
31       "validation": {
32            "const": "API Support"
33        }
34    },
35  },
36  "nonRenderableFiles": [
37    "src/api/middlewares/*.*",
38    "lib/lib/config.js"
39  ],
40  "generator": "<2.0.0",
41  "filters": [
42    "my-package-with-filters"
43  ],
44  "hooks": {
45    "@asyncapi/generator-hooks": "hookFunctionName",
46    "my-custom-hooks-package": ["myHook", "andAnotherOne"]
47  }
48}

Note: If both .ageneratorrc file and the generator property in package.json exist, the configuration from .ageneratorrc will override the package.json configuration.

The generator property from package.json file and must contain a JSON object and the ageneratorrc file must contain a YAML object that may have the following information:

NameTypeDescription
rendererStringIts value can be either react or nunjucks (default).
apiVersionStringDetermines which major version of the Parser-API the template uses. For example, v2 for v2.x.x. If not specified, the Generator assumes the template is not compatible with the Parser-API so it will use the Parser-JS v1 API. For templates that need to support AsyncAPI specification v3 make sure to use v3 Parser-API. If the template uses a version of the Parser-API that is not supported by the Generator, the Generator will throw an error.
supportedProtocols[String]A list with all the protocols this template supports.
parametersObject[String, Object]An object with all the parameters that can be passed when generating the template. When using the command line, it's done by indicating --param name=value or -p name=value.
parameters[param].descriptionStringA user-friendly description about the parameter.
parameters[param].defaultAnyDefault value of the parameter if not specified. Shouldn't be used for mandatory required=true parameters.
parameters[param].requiredBooleanWhether the parameter is required or not.
conditionalFilesObject[String, Object]An object containing all the file paths that should be conditionally rendered. Each key represents a file path and each value must be an object with the keys subject and validation. The file path should be relative to the template directory inside the template. Note: It is deprecated and will be removed with future releases. Use conditionalGeneration instead.
conditionalFiles[filePath].subjectStringThe subject is a JMESPath query to grab the value you want to apply the condition to. It queries an object with the whole AsyncAPI document and, when specified, the given server. The object looks like this: { asyncapi: { ... }, server: { ... } }. If the template supports the server parameter, you can access server details, for example, server.protocol. During validation with conditionalFiles, only the server that the template user selected is available in the specification file. For more information about server parameter read about special parameters. Note: It is deprecated and will be removed with future releases. Use conditionalGeneration instead.
conditionalFiles[filePath].validationObjectThe validation is a JSON Schema Draft 07 object. This JSON Schema definition will be applied to the JSON value resulting from the subject query. If validation doesn't have errors, the condition is met, and therefore the given file will be rendered. Otherwise, the file is ignored. Check JSON Schema Validation for a list of all possible validation keywords. Note: It is deprecated and will be removed with future releases. Use conditionalGeneration instead.
conditionalGenerationObject[String, { subject?: String, parameter?: String, validation: Object }]An object containing all the file paths or directory names that should be conditionally rendered. Each key represents a file path or directory name and each value must be an object with the keys subject, parameter and validation. You can use either subject or parameter according to the use case. The path should be relative to the template directory inside the template. Note: conditionalGeneration and conditionalFile are mutually exclusive, which means both cannot be configured at the same time in the template.
conditionalGeneration[filePath/directoryName].subjectStringThe subject is a JMESPath query to grab the value you want to apply the condition to. It queries an object with the whole AsyncAPI document and, when specified, the given server. The object looks like this: { asyncapi: { ... }, server: { ... } }. If the template supports the server parameter, you can access server details like, for example, protocol this way: server.protocol. During validation with conditionalGeneration, only the server that the template user selected is available in the specification file. For more information about the server parameter read about special parameters.
conditionalGeneration[filePath/directoryName].parameterStringThe parameter is the name of a custom template parameter passed through templateParams that controls whether a specific file or folder should be included in the generated output. You must define a validation rule using a JSON Schema fragment to apply the condition. For example, if you define "parameter": "includeDocs" with "validation": { "const": true }, the corresponding folder (e.g., docs/) will only be generated when the user passes { includeDocs: true }. If includeDocs is false, it will be skipped.
conditionalGeneration[filePath/directoryName].validationObject (JSON Schema fragment)The validation defines the condition under which the file or directory will be generated. It must be a valid JSON Schema fragment that validates the value of the parameter. For example, if you want to include a folder only when includeDocs is true, use "validation": { "const": true }. You can also use more complex validation logic, like "enum": ["yes", "true"] or "type": "string" with a "pattern" constraint. If the parameter fails validation, the file or folder will not be included in the generated output. This allows for powerful and flexible control over template generation based on user input.
nonRenderableFiles[String]A list of file paths or globs that must be copied "as-is" to the target directory, i.e., without performing any rendering process. This is useful when you want to copy binary files.
generator[String]A string representing the generator version-range the template is compatible with. This value must follow the semver syntax. E.g., >=1.0.0, >=1.0.0 <=2.0.0, ~1.0.0, ^1.0.0, 1.0.0, etc. Read more about semver.
filters[String]A list of modules containing functions that can be used as Nunjucks filters. In case of external modules, remember they need to be added as a dependency in package.json of your template.
hooksObject[String, String] or Object[String, Array[String]]A list of modules containing hooks, except for the ones you keep locally in your template in the default location. For each module you must specify the exact name of the hook that should be used in the template. For a single hook, you can specify it as a string; for more hooks, you must pass an array of strings. In the case of external modules, remember they need to be added as a dependency in package.json of your template. There is also an official hooks library always included in the generator. As this is a library of multiple hooks, you still need to explicitly specify in the configuration which one you want to use. Use @asyncapi/generator-hooks as the library name.

Special parameters

There are some template parameters that have a special meaning:

NameDescription
serverIt is used to let the template know which server from the AsyncAPI specification file you want to use. In some cases, this may be required. For instance, when generating code that connects to a specific server. Use this parameter in case your template relies on users' information about what server from the specification file they want to use during generation. You also need this parameter if you want to use server.protocol notation within conditionalGeneration configuration option. Once you decide to specify this parameter for your template, it is recommended you make it a mandatory parameter otherwise a feature like conditionalGeneration is not going to work if your users do not use this parameter obligatory.
Was this helpful?
Help us improve the docs by adding your contribution.
OR
Github:AsyncAPICreate Issue on GitHub