Warning
Hooks are now part of generator repository and also out of the box integrated with the generator, so no need to set it as dependency any more: https://github.com/asyncapi/generator/releases/tag/%40asyncapi%2Fgenerator%402.5.0. NPM package is no longer published.
This is a library with generator hooks that are used in more than one template. Use these hooks to not double your work. Read Generator documentation to understand how to configure your template to use external hooks.
This library consists of the following hooks:
Hook name | Hook type | Description |
---|---|---|
createAsyncapiFile |
generate:after |
It creates AsyncAPI file with content of the spec file passed to the generator. By default it created the file in the root of the generation output directory. This hook also supports custom parameters that user can pass to template generation. Parameter called asyncapiFileDir allows user to specify the location where spec file should be created. To make your template users use this parameter, you need to add it to the configuration of your template like other parameters |
- Add
@asyncapi/generator-hooks
todependencies
of your templatenpm install @asyncapi/generator-hooks --save
- Configure your template what hooks you want to use in the template configuration file:
{ "hooks": { "@asyncapi/generator-hooks": "createAsyncapiFile" } }
- (Optional) In case the hook that you want to use supports parameters, specify in the configuration what parameters users can specify:
{ "parameters": { "asyncapiFileDir": { "description": "Custom location of the AsyncAPI file that you provided as an input in generation. By default it is located in the root of the output directory", "required": false } }, "hooks": { "@asyncapi/generator-hooks": "createAsyncapiFile" } }