From 0e3478b46ebb086d08fe7e41a87de8110d99e08d Mon Sep 17 00:00:00 2001 From: Bedi Gupta Date: Mon, 14 Oct 2024 15:01:21 +0530 Subject: [PATCH 1/4] refactor: use optional chaining in template validator (#1300) --- apps/generator/lib/templateConfigValidator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/generator/lib/templateConfigValidator.js b/apps/generator/lib/templateConfigValidator.js index 3b57ef759..9e075b98b 100644 --- a/apps/generator/lib/templateConfigValidator.js +++ b/apps/generator/lib/templateConfigValidator.js @@ -97,7 +97,7 @@ function getParamSuggestion(wrongParam, configParams) { * @param {Object} templateParams All parameters provided to generator */ function isProvidedParameterSupported(configParams, templateParams) { - const wrongParams = Object.keys(templateParams || {}).filter(key => !configParams || !configParams[key]); + const wrongParams = Object.keys(templateParams || {}).filter(key => !configParams?.[key]); if (!wrongParams.length) return; if (!configParams) throw new Error('This template doesn\'t have any params.'); From 254b07247f7d90f81ba6bd10d00a7eb478ce0f1d Mon Sep 17 00:00:00 2001 From: Bedi Gupta Date: Mon, 14 Oct 2024 21:50:55 +0530 Subject: [PATCH 2/4] refactor: use optional chaining in template params validation (#1299) Co-authored-by: Lukasz Gornicki --- apps/generator/lib/generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/generator/lib/generator.js b/apps/generator/lib/generator.js index cb4ffe950..8b2592a6f 100644 --- a/apps/generator/lib/generator.js +++ b/apps/generator/lib/generator.js @@ -134,7 +134,7 @@ class Generator { Object.defineProperty(this.templateParams, key, { enumerable: true, get() { - if (!self.templateConfig.parameters || !self.templateConfig.parameters[key]) { + if (!self.templateConfig.parameters?.[key]) { throw new Error(`Template parameter "${key}" has not been defined in the package.json file under generator property. Please make sure it's listed there before you use it in your template.`); } return templateParams[key]; From 298479a5773e4c4860d927d42b513f5f6018f1b4 Mon Sep 17 00:00:00 2001 From: Bedi Gupta Date: Mon, 14 Oct 2024 22:05:19 +0530 Subject: [PATCH 3/4] refactor: simplify variable initialization in tests (#1297) Co-authored-by: Lukasz Gornicki --- apps/generator/test/renderer.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/generator/test/renderer.test.js b/apps/generator/test/renderer.test.js index f6c0c6458..bd1a6489e 100644 --- a/apps/generator/test/renderer.test.js +++ b/apps/generator/test/renderer.test.js @@ -10,8 +10,8 @@ jest.mock('@asyncapi/generator-react-sdk'); describe('React renderer', () => { describe('saveRenderedReactContent', () => { - let util = undefined; - let AsyncReactSDK = undefined; + let util; + let AsyncReactSDK; beforeAll(() => { util = require('../lib/utils'); AsyncReactSDK = require('@asyncapi/generator-react-sdk'); From 25c4e53c06282e21f037ff61485cc3c594e043ac Mon Sep 17 00:00:00 2001 From: Bedi Gupta Date: Tue, 15 Oct 2024 13:25:53 +0530 Subject: [PATCH 4/4] refactor: better readability of `buildLineCore` filter (#1301) Co-authored-by: Lukasz Gornicki --- apps/nunjucks-filters/src/customFilters.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/nunjucks-filters/src/customFilters.js b/apps/nunjucks-filters/src/customFilters.js index 83ef06fbb..0914c821a 100644 --- a/apps/nunjucks-filters/src/customFilters.js +++ b/apps/nunjucks-filters/src/customFilters.js @@ -150,9 +150,11 @@ function docline(field, fieldName, scopePropName) { const getPName = (pName) => pName ? `${pName}.` : ''; const buildLineCore = (type, def, pName, fName) => { - return `* @param {${type}} ${pName}${fName}${def !== undefined ? `=${def}` : ''}`; + const paramName = `${pName}${fName}`; + const defaultValue = def !== undefined ? `=${def}` : ''; + return `* @param {${type}} ${paramName}${defaultValue}`; }; - + const buildLine = (f, fName, pName) => { const type = getType(f); const def = getDefault(f, type);