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 variableschannelandchannelName. Where thechannelcontains the current channel being rendered.$$message$$, within the template-file you have access to two variablesmessageandmessageName. Wheremessagecontains the current message being rendered.$$schema$$, within the template-file you have access to two variablesschemaandschemaName. Whereschemacontains the current schema being rendered. Only schemas from Components object are used.$$everySchema$$, within the template-file you have access to two variablesschemaandschemaName. Whereschemacontains 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 variablesschemaandschemaName. Whereschemacontains the current schema being rendered. All the Schema objects with type object is used.$$parameter$$, within the template-file you have access to two variablesparameterandparameterName. Where theparametercontains the current parameter being rendered.$$securityScheme$$, within the template-file you have access to two variablessecuritySchemeandsecuritySchemeName. WheresecuritySchemecontains 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 4Schema 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 12components: 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 2Schema name is 'peoplePayload' and properties are: - people
and
1 2Schema 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 6export default function({ asyncapi }) { return [ <File name={`file1.html`}>Content</File>, <File name={`file2.html`}>Content</File> ] }