From a7611abebb09f991ae06eb4e8d0b887f6cf26eef Mon Sep 17 00:00:00 2001 From: Lukas Mertens Date: Thu, 8 Feb 2024 22:24:10 +0100 Subject: [PATCH] feat: added $$operation$$ file template --- docs/file-templates.md | 1 + lib/generator.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/docs/file-templates.md b/docs/file-templates.md index 5ba4a9687..137a91456 100644 --- a/docs/file-templates.md +++ b/docs/file-templates.md @@ -6,6 +6,7 @@ weight: 140 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`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#channel) and [`channelName`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#channels). Where the `channel` contains the current channel being rendered. + - `$$operation$$`, within the template-file you have access to two variables [`operation`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#operation) and [`operationName`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#operations). Where the `operation` contains the current operation being rendered. - `$$message$$`, within the template-file you have access to two variables [`message`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#message) and [`messageName`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#message). Where `message` contains the current message being rendered. - `$$schema$$`, within the template-file you have access to two variables [`schema`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#schema) and [`schemaName`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#schema). Where `schema` contains the current schema being rendered. Only schemas from [Components object](https://www.asyncapi.com/docs/reference/specification/latest#componentsObject) are used. - `$$everySchema$$`, within the template-file you have access to two variables [`schema`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#schema) and [`schemaName`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#schemas). Where `schema` contains the current schema being rendered. Every [Schema object](https://www.asyncapi.com/docs/specifications/2.0.0/#schemaObject) from the entire AsyncAPI file is used. diff --git a/lib/generator.js b/lib/generator.js index c00c2e0be..1ccfde514 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -731,6 +731,7 @@ class Generator { objectSchema: convertCollectionToObject(asyncapiDocument.schemas().all().filter(schema => schema.type() === 'object'), 'id'), parameter: convertMapToObject(this.getAllParameters(asyncapiDocument)), everySchema: convertCollectionToObject(asyncapiDocument.schemas().all(), 'id'), + operation: convertCollectionToObject(asyncapiDocument.operations().all(), 'id'), }; } else { const objectSchema = {}; @@ -743,6 +744,7 @@ class Generator { objectSchema, parameter: convertMapToObject(this.getAllParameters(asyncapiDocument)), everySchema: convertMapToObject(asyncapiDocument.allSchemas()), + operation: convertCollectionToObject(asyncapiDocument.allOperations()), }; }