From fb666018cf8c79de587e7b5fa3164446da545894 Mon Sep 17 00:00:00 2001 From: Chakraborty Date: Thu, 3 Nov 2022 18:01:39 +0530 Subject: [PATCH 1/2] Added support for null params --- util/docs/macros/index.mjs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/util/docs/macros/index.mjs b/util/docs/macros/index.mjs index 537a1f5f..c8d85134 100644 --- a/util/docs/macros/index.mjs +++ b/util/docs/macros/index.mjs @@ -980,6 +980,16 @@ function getExternalSchemaLinks(json = {}, schemas = {}, options = {}) { return links } +function isNextParamNotRequired(params, i, p) { + let nonReqParamsArray = []; + for (let index = i; index < params.length; index++){ + if (p.required === false) { + nonReqParamsArray.push(p); + } + } + return nonReqParamsArray.length === (params.length - i); +} + function generateJavaScriptExample(example, m, moduleJson = {}, templates = {}) { if (m.name.match(/^on[A-Z]/)) { if (isProviderMethod(m)) { @@ -989,7 +999,18 @@ function generateJavaScriptExample(example, m, moduleJson = {}, templates = {}) } } - const formatParams = (params, delimit, pretty = false) => params.map(p => JSON.stringify((example.params.find(x => x.name === p.name) || { value: null }).value, null, pretty ? ' ' : null)).join(delimit) + const formatParams = (params, delimit, pretty = false) => { + // added check to handle the scenario when parameter is optional + // and it's coming as null in the doc + return params.map((p, index) => { + if (!p.required && isNextParamNotRequired(params, index, p)) { + return ''; + } else { + return JSON.stringify((example.params.find(x => x.name === p.name) || { value: null }).value, null, pretty ? ' ' : null); + } + }).join(delimit); + } + let indent = ' '.repeat(getTitle(moduleJson).length + m.name.length + 2) let params = formatParams(m.params, ', ') if (params.length + indent > 80) { From 3a8ddf6d1d18d893e93de60b47186b1ff44062c4 Mon Sep 17 00:00:00 2001 From: Chakraborty Date: Thu, 3 Nov 2022 18:04:55 +0530 Subject: [PATCH 2/2] let to const --- util/docs/macros/index.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/docs/macros/index.mjs b/util/docs/macros/index.mjs index c8d85134..e0a2e8bf 100644 --- a/util/docs/macros/index.mjs +++ b/util/docs/macros/index.mjs @@ -981,7 +981,7 @@ function getExternalSchemaLinks(json = {}, schemas = {}, options = {}) { } function isNextParamNotRequired(params, i, p) { - let nonReqParamsArray = []; + const nonReqParamsArray = []; for (let index = i; index < params.length; index++){ if (p.required === false) { nonReqParamsArray.push(p);