Skip to content

Commit

Permalink
fix(markdown-builder): guard against enum being not an array
Browse files Browse the repository at this point in the history
fixes #458
  • Loading branch information
trieloff committed Nov 14, 2022
1 parent c9141b3 commit aa46ac4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ export default function build({
(prop) => {
// this is a linked property
if (schema[s.meta]
&& typeof schema[s.meta][prop.name] === 'object'
&& schema[s.meta][prop.name].link
&& schema[s.meta][prop.name].text) {
&& typeof schema[s.meta][prop.name] === 'object'
&& schema[s.meta][prop.name].link
&& schema[s.meta][prop.name].text) {
return tableCell(link(rewritelinks(schema[s.meta][prop.name].link), i18n`open original schema`, [text(schema[s.meta][prop.name].text)]));
}
const value = schema[s.meta] ? schema[s.meta][prop.name] : undefined;
Expand Down Expand Up @@ -398,11 +398,11 @@ export default function build({
return [listItem(paragraph(text(i18n`and all following items may follow any schema`)))];
} else if (typeof additional === 'object') {
return [listItem(paragraph([text(i18n`and all following items must follow the schema: `),
link(
`${additional[s.slug]}.md`,
i18n`check type definition`,
text(gentitle(additional[s.titles], additional[keyword`type`])),
)]))];
link(
`${additional[s.slug]}.md`,
i18n`check type definition`,
text(gentitle(additional[s.titles], additional[keyword`type`])),
)]))];
}
return [];
})(),
Expand Down Expand Up @@ -579,10 +579,10 @@ export default function build({
tableCell(text(i18n`Value`)),
tableCell(text(i18n`Explanation`)),
]),
...schema[keyword`enum`].map((value) => tableRow([
...(Array.isArray(schema[keyword`enum`]) ? schema[keyword`enum`].map((value) => tableRow([
tableCell(inlineCode(JSON.stringify(value))),
tableCell(text(metas[Array.isArray(value) ? JSON.stringify(value) : value] || '')),
])),
])) : []),
]));
}

Expand Down Expand Up @@ -664,12 +664,12 @@ export default function build({
if (schema[keyword`minContains`] !== undefined && schema[keyword`contains`]) {
// console.log('minContains!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`minimum number of contained items`)), text(': '), text(`${i18n`this array may not contain fewer than ${String(schema[keyword`minContains`])} items that validate against the schema:`} `),
link(`${schema[keyword`contains`][s.slug]}.md`, i18n`check type definition`, text(gentitle(schema[keyword`contains`][s.titles], schema[keyword`contains`][keyword`type`])))]));
link(`${schema[keyword`contains`][s.slug]}.md`, i18n`check type definition`, text(gentitle(schema[keyword`contains`][s.titles], schema[keyword`contains`][keyword`type`])))]));
}
if (schema[keyword`maxContains`] !== undefined && schema[keyword`contains`]) {
// console.log('maxContains!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`maximum number of contained items`)), text(': '), text(`${i18n`this array may not contain more than ${String(schema[keyword`maxContains`])} items that validate against the schema:`} `),
link(`${schema[keyword`contains`][s.slug]}.md`, i18n`check type definition`, text(gentitle(schema[keyword`contains`][s.titles], schema[keyword`contains`][keyword`type`])))]));
link(`${schema[keyword`contains`][s.slug]}.md`, i18n`check type definition`, text(gentitle(schema[keyword`contains`][s.titles], schema[keyword`contains`][keyword`type`])))]));
}

// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.5
Expand Down

0 comments on commit aa46ac4

Please sign in to comment.