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 variableschannel
andchannelName
. Where thechannel
contains the current channel being rendered.$$message$$
, within the template-file you have access to two variablesmessage
andmessageName
. Wheremessage
contains the current message being rendered.$$schema$$
, within the template-file you have access to two variablesschema
andschemaName
. Whereschema
contains the current schema being rendered. Only schemas from Components object are used.$$everySchema$$
, within the template-file you have access to two variablesschema
andschemaName
. Whereschema
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 variablesschema
andschemaName
. Whereschema
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 variablesparameter
andparameterName
. Where theparameter
contains the current parameter being rendered.$$securityScheme$$
, within the template-file you have access to two variablessecurityScheme
andsecuritySchemeName
. WheresecurityScheme
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> ] }