/generator

Use your AsyncAPI definition to generate literally anything. Markdown documentation, Node.js code, HTML documentation, anything!

Primary LanguageHTMLApache License 2.0Apache-2.0

AsyncAPI Generator

Use your AsyncAPI definition to generate literally anything. Markdown documentation, Node.js code, HTML documentation, anything!



Install

npm install -g asyncapi-generator

Usage

From the command-line interface (CLI)

  Usage: ag [options] <asyncapi> <template>


  Options:

    -V, --version                 output the version number
    -o, --output <outputDir>      directory where to put the generated files (defaults to current directory)
    -t, --templates <templatesDir> directory where templates are located (defaults to internal templates directory)
    --params <templateParams>     json object with additional params to pass to templates    
    -h, --help                    output usage information

Examples

The shortest possible syntax:

ag asyncapi.yaml markdown

Specify where to put the result:

ag -o ./docs asyncapi.yaml markdown

Passing parameters to templates:

ag -o ./docs --params '{ "title": "Hello from param" }' asyncapi.yaml markdown

In the template you can use it like this: {{ params.title }}

As a module

.generateTemplateFile(options) : String

Generates a file of a given template, and returns the result as a string.

Parameters
Name Type Required Description
options object Yes An object containing all the options.
options.templatesDir string No Directory where to find the templates. Defaults to internal templates directory.
options.template string Yes Name of the template you want to use.
options.file string Yes Path to the file you want to generate.
options.config object Yes An object containing configuration options.
options.config.asyncapi string|object Yes Path to the AsyncAPI file to use.
Example
const generator = require('asyncapi-generator');

generator.generateTemplateFile({
  template: 'html',
  file: 'index.html',
  config: {
    asyncapi: path.resolve(__dirname, 'asyncapi.yml'),
  }
})
  .then((result) => {
    // `result` is a string containing the generated file.
    console.log(result);
  })
  .catch(console.error);

.getTemplateFile(options) : String

Gets a file of a given template, and returns the its content as a string.

Parameters
Name Type Required Description
options object Yes An object containing all the options.
options.templatesDir string No Directory where to find the templates. Defaults to internal templates directory.
options.template string Yes Name of the template you want to use.
options.file string Yes Path to the file you want to generate.
Example
const generator = require('asyncapi-generator');

generator.getTemplateFile({
  template: 'html',
  file: 'css/main.css',
})
  .then((content) => {
    console.log(result);
  })
  .catch(console.error);

Requirements

  • Node.js v7.6+

Contributing

Contributions are more than welcome. If you want to make a contribution, please make sure you go through the following steps:

  1. Pick or create an issue. It's always a good idea to leave a message saying that you're going to work on it before you start any actual work.
  2. Fork the repository and work there.
  3. Open a Pull Request pointing to master branch.
  4. A maintainer will review and, eventually, merge your Pull Request. Please, be patient as most of us are doing this in our spare time.

Author

Fran Méndez (@fmvilas)