diff --git a/util/docs/macros/index.mjs b/util/docs/macros/index.mjs index 1e086152..a0e93328 100644 --- a/util/docs/macros/index.mjs +++ b/util/docs/macros/index.mjs @@ -925,6 +925,16 @@ function getExternalSchemaLinks(json = {}, schemas = {}, options = {}) { return links } +function isNextParamNotRequired(params, i, p) { + const 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 (isProviderInterfaceMethod(m)) { @@ -934,7 +944,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) {