@asyncapi/generator@2.7.0
Minor Changes
What's New
-
Introduced a new
conditionalGeneration
configuration for templates (@AayushSaini101). Supports conditional generation of both files and folders. It enables conditions based on values from the AsyncAPI document (subject
) and custom templateparameters
. Theparameter
allows users to pass custom flags or values at generation time (via the CLI or programmatically) to control what parts of the template get rendered. -
Addition of new config file
.ageneratorrc
(@ItshMoh): Previously, generator configuration had to be defined in thepackage.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 inpackage.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 inpackage.json
.The
.ageneratorrc
file should be in YAML format.Earlier, the
package.json
for the Python WebSocket client looked like this:{ "name": "@asyncapi/template-python-websocket-client", "version": "0.0.1", "description": "This is a template generating Python websocket client", // ...other configuration... "generator": { "renderer": "react", "apiVersion": "v3", "generator": ">=1.3.0 <3.0.0", "parameters": { "server": { "description": "The name of the server described in AsyncAPI document", "required": true }, "clientFileName": { "description": "The name of the generated client file", "required": false, "default": "client.py" }, "appendClientSuffix": { "description": "Add 'Client' suffix at the end of the class name. This option has no effect if 'customClientName' is specified.", "required": false, "default": false }, "customClientName": { "description": "The custom name for the generated client class", "required": false } } } }
Now after the introduction of the
.ageneratorrc
file, thepackage.json
can be simplified by removing the generator configuration:{ "name": "@asyncapi/template-python-websocket-client", "version": "0.0.1", "description": "This is a template generating Python websocket client", "scripts": { "test": "npm run test:cleanup && jest --coverage", "test:update": "npm run test -- -u", "test:cleanup": "rimraf \"test/temp\"", "lint": "eslint --max-warnings 0 --config ../../../../../.eslintrc --ignore-path ../../../../../.eslintignore .", "lint:fix": "eslint --fix --max-warnings 0 --config ../../../../../.eslintrc --ignore-path ../../../../../.eslintignore ." }, "author": "Lukasz Gornicki <lpgornicki@gmail.com>", "license": "Apache-2.0", "dependencies": { "@asyncapi/generator-react-sdk": "^1.1.2", "@asyncapi/generator-helpers": "1.0.0" }, "devDependencies": { "@asyncapi/parser": "^3.0.14", "@babel/cli": "^7.25.9", "@babel/core": "^7.26.0", "@babel/preset-env": "^7.26.0", "@babel/preset-react": "^7.25.9", "jest-esm-transformer": "^1.0.0", "@asyncapi/generator": "*", "eslint": "^6.8.0", "eslint-plugin-jest": "^23.8.2", "eslint-plugin-react": "^7.34.1", "eslint-plugin-sonarjs": "^0.5.0", "rimraf": "^3.0.2" }, "jest": { "moduleFileExtensions": ["js", "json", "jsx"], "transform": { "^.+\\.jsx?$": "babel-jest" }, "moduleNameMapper": { "^nimma/legacy$": "<rootDir>/../../../../../node_modules/nimma/dist/legacy/cjs/index.js", "^nimma/(.*)": "<rootDir>/../../../../../node_modules/nimma/dist/cjs/$1" } }, "babel": { "presets": [ "@babel/preset-env", [ "@babel/preset-react", { "runtime": "automatic" } ] ] } }
And the equivalent
.ageneratorrc
file would be:renderer: react apiVersion: v3 generator: ">=1.3.0 <3.0.0" parameters: server: description: The name of the server described in AsyncAPI document required: true clientFileName: description: The name of the generated client file required: false default: client.py appendClientSuffix: description: Add 'Client' suffix at the end of the class name. This option has no effect if 'customClientName' is specified. required: false default: false customClientName: description: The custom name for the generated client class required: false
Deprecation notice
- The existing
conditionalFile
configuration is now deprecated and will be removed in a future release. - To migrate, replace
conditionalFile
withconditionalGeneration
in your template configuration.