Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for null params #71

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion util/docs/macros/index.mjs
Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down