From c246dd2eb49b0270a8c8f14a2d50ebd6c6818de6 Mon Sep 17 00:00:00 2001 From: chinmayshewale Date: Fri, 26 May 2023 04:05:06 +0530 Subject: [PATCH 1/2] Doc changes --- docs/api.md | 46 +++++++++++++++++++++++++++++++++++++++++++--- lib/generator.js | 31 +++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/docs/api.md b/docs/api.md index b51bc16d2..3955efc8d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -4,6 +4,22 @@ weight: 75 --- Reference API documentation for AsyncAPI Generator library. +## Classes + +
+
Generator
+
+
+ +## Typedefs + +
+
TemplateRenderMetadata : Object
+
+
TemplateRenderResult : Object
+
+
+ @@ -29,9 +45,9 @@ Reference API documentation for AsyncAPI Generator library. * [.originalAsyncAPI](#Generator+originalAsyncAPI) : `String` * [.generate(asyncapiDocument)](#Generator+generate) ⇒ `Promise` * [.configureTemplate()](#Generator+configureTemplate) - * [.generateFromString(asyncapiString, [parseOptions])](#Generator+generateFromString) ⇒ `Promise` - * [.generateFromURL(asyncapiURL)](#Generator+generateFromURL) ⇒ `Promise` - * [.generateFromFile(asyncapiFile)](#Generator+generateFromFile) ⇒ `Promise` + * [.generateFromString(asyncapiString, [parseOptions])](#Generator+generateFromString) ⇒ `Promise.<(TemplateRenderResult|undefined)>` + * [.generateFromURL(asyncapiURL)](#Generator+generateFromURL) ⇒ `Promise.<(TemplateRenderResult|undefined)>` + * [.generateFromFile(asyncapiFile)](#Generator+generateFromFile) ⇒ `Promise.<(TemplateRenderResult|undefined)>` * [.installTemplate([force])](#Generator+installTemplate) * _static_ * [.getTemplateFile(templateName, filePath, [templatesDir])](#Generator.getTemplateFile) ⇒ `Promise` @@ -342,3 +358,27 @@ const content = await Generator.getTemplateFile('@asyncapi/html-template', 'part const Generator = require('@asyncapi/generator'); const content = await Generator.getTemplateFile('@asyncapi/html-template', 'partials/content.html', '~/my-templates'); ``` + + + +* TemplateRenderMetadata : `Object`** : +**Kind**: global typedef +**Properties** + +| Name | Type | +| --- | --- | +| fileName | `string` | +| permissions | `string` | + + + + +* TemplateRenderResult : `Object`** : +**Kind**: global typedef +**Properties** + +| Name | Type | +| --- | --- | +| content | `string` | +| metadata | [`TemplateRenderMetadata`](#TemplateRenderMetadata) | + diff --git a/lib/generator.js b/lib/generator.js index fd34100ea..68acdbb20 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -213,6 +213,17 @@ class Generator { this.nunjucks = configureNunjucks(this.debug, this.templateDir); } } + /** + * @typedef {Object} TemplateRenderMetadata + * @property {string} fileName + * @property {string} permissions + */ + + /** + * @typedef {Object} TemplateRenderResult + * @property {string} content + * @property {TemplateRenderMetadata} metadata + */ /** * Generates files from a given template and AsyncAPI string. @@ -250,7 +261,7 @@ class Generator { * * @param {String} asyncapiString AsyncAPI string to use as source. * @param {Object} [parseOptions={}] AsyncAPI Parser parse options. Check out {@link https://www.github.com/asyncapi/parser-js|@asyncapi/parser} for more information. - * @return {Promise} + * @return {Promise} */ async generateFromString(asyncapiString, parseOptions = {}) { if (!asyncapiString || typeof asyncapiString !== 'string') throw new Error('Parameter "asyncapiString" must be a non-empty string.'); @@ -288,7 +299,7 @@ class Generator { * } * * @param {String} asyncapiURL Link to AsyncAPI file - * @return {Promise} + * @return {Promise} */ async generateFromURL(asyncapiURL) { const doc = await fetchSpec(asyncapiURL); @@ -315,7 +326,7 @@ class Generator { * } * * @param {String} asyncapiFile AsyncAPI file to use as source. - * @return {Promise} + * @return {Promise} */ async generateFromFile(asyncapiFile) { const doc = await readFile(asyncapiFile, { encoding: 'utf8' }); @@ -436,7 +447,7 @@ class Generator { } }); } - + if (asyncapiDocument.hasComponents()) { for (const [key, value] of Object.entries(asyncapiDocument.components().parameters())) { parameters.set(key, value); @@ -692,12 +703,12 @@ class Generator { */ maybeRenameSourceFile(sourceFile) { switch (path.basename(sourceFile)) { - case GIT_IGNORE_FILENAME: - return path.join(path.dirname(sourceFile), '.gitignore'); - case NPM_IGNORE_FILENAME: - return path.join(path.dirname(sourceFile), '.npmignore'); - default: - return sourceFile; + case GIT_IGNORE_FILENAME: + return path.join(path.dirname(sourceFile), '.gitignore'); + case NPM_IGNORE_FILENAME: + return path.join(path.dirname(sourceFile), '.npmignore'); + default: + return sourceFile; } } From b7c7e2e9a3f169ed2e451080fb835d9f93628298 Mon Sep 17 00:00:00 2001 From: chinmayshewale Date: Fri, 26 May 2023 05:17:30 +0530 Subject: [PATCH 2/2] lint --- lib/generator.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index 68acdbb20..e2fb75162 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -703,12 +703,12 @@ class Generator { */ maybeRenameSourceFile(sourceFile) { switch (path.basename(sourceFile)) { - case GIT_IGNORE_FILENAME: - return path.join(path.dirname(sourceFile), '.gitignore'); - case NPM_IGNORE_FILENAME: - return path.join(path.dirname(sourceFile), '.npmignore'); - default: - return sourceFile; + case GIT_IGNORE_FILENAME: + return path.join(path.dirname(sourceFile), '.gitignore'); + case NPM_IGNORE_FILENAME: + return path.join(path.dirname(sourceFile), '.npmignore'); + default: + return sourceFile; } }