AsyncAPI Conf on Tour 2023

Madrid Edition

October, 2023 | Madrid, Spain

5 days until the end for Call for Speakers.
On this page

File templates

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

It is possible to generate files for each specific object in your AsyncAPI documentation. For example, you can specify a filename like $$channel$$.js to generate a file for each channel defined in your AsyncAPI. The following file-template names and extra variables in them are available:

  • $$channel$$, within the template-file you have access to two variables channel and channelName. Where the channel contains the current channel being rendered.
  • $$message$$, within the template-file you have access to two variables message and messageName. Where message contains the current message being rendered.
  • $$schema$$, within the template-file you have access to two variables schema and schemaName. Where schema contains the current schema being rendered. Only schemas from Components object are used.
  • $$everySchema$$, within the template-file you have access to two variables schema and schemaName. Where schema contains the current schema being rendered. Every Schema object from the entire AsyncAPI file is used.
  • $$objectSchema$$, within the template-file you have access to two variables schema and schemaName. Where schema contains the current schema being rendered. All the Schema objects with type object is used.
  • $$parameter$$, within the template-file you have access to two variables parameter and parameterName. Where the parameter contains the current parameter being rendered.
  • $$securityScheme$$, within the template-file you have access to two variables securityScheme and securitySchemeName. Where securityScheme contains the current security scheme being rendered.

The file name will be equal to *Name variable.

Example

The file name is $$schema$$.txt, the content of this file is:

1
2
3
4
Schema name is '{{schemaName}}' and properties are:
{% for propName, prop in schema.properties() %}
- {{prop.uid()}}
{% endfor %}

With following AsyncAPI:

1
2
3
4
5
6
7
8
9
10
11
12
components:
  schemas: 
    peoplePayload:
      type: object
      properties:
        event:
          $ref: "#/components/schemas/people"
    people:
      type: object
      properties:
        id:
          type: integer

The generator creates two files peoplePayload.txt and people.txt with the following content:

1
2
Schema name is 'peoplePayload' and properties are:
- people

and

1
2
Schema name is 'people' and properties are:
- id

React

The above way of rendering file templates works for both nunjucks and react render engines, but react also has another, more generic way to render multiple files. It is enough to return an array of File components in the rendering component. See the following example:

1
2
3
4
5
6
export default function({ asyncapi }) {
  return [
    <File name={`file1.html`}>Content</File>,
    <File name={`file2.html`}>Content</File>
  ]
}
Was this helpful?
Help us improve the docs by adding your contribution.
OR
Github:AsyncAPICreate Issue on GitHub