Skip to content

Commit

Permalink
fix(markdown): constraint values can be zero now
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 14, 2019
1 parent 1c11bcb commit 2e057fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,33 +519,33 @@ function build({


// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.2
if (schema[keyword`multipleOf`]) {
if (schema[keyword`multipleOf`] !== undefined) {
// console.log('multiple!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`multiple of`)), text(': '), text(i18n`the value of this number must be a multiple of: `), inlineCode(String(schema[keyword`multipleOf`]))]));
}
if (schema[keyword`maximum`]) {
if (schema[keyword`maximum`] !== undefined) {
// console.log('maximum!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`maximum`)), text(': '), text(i18n`the value of this number must smaller than or equal to: `), inlineCode(String(schema[keyword`maximum`]))]));
}
if (schema[keyword`exclusiveMaximum`]) {
if (schema[keyword`exclusiveMaximum`] !== undefined) {
// console.log('exclusiveMaximum!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`maximum (exclusive)`)), text(': '), text(i18n`the value of this number must be smaller than: `), inlineCode(String(schema[keyword`exclusiveMaximum`]))]));
}
if (schema[keyword`minimum`]) {
if (schema[keyword`minimum`] !== undefined) {
// console.log('minimum!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`minimum`)), text(': '), text(i18n`the value of this number must greater than or equal to: `), inlineCode(String(schema[keyword`minimum`]))]));
}
if (schema[keyword`exclusiveMinimum`]) {
if (schema[keyword`exclusiveMinimum`] !== undefined) {
// console.log('exclusiveMinimum!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`minimum (exclusive)`)), text(': '), text(i18n`the value of this number must be greater than: `), inlineCode(String(schema[keyword`exclusiveMinimum`]))]));
}

// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.3
if (schema[keyword`maxLength`]) {
if (schema[keyword`maxLength`] !== undefined) {
// console.log('maxLength!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`maximum length`)), text(': '), text(i18n`the maximum number of characters for this string is: `), inlineCode(String(schema[keyword`maxLength`]))]));
}
if (schema[keyword`minLength`]) {
if (schema[keyword`minLength`] !== undefined) {
// console.log('minLength!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`minimum length`)), text(': '), text(i18n`the minimum number of characters for this string is: `), inlineCode(String(schema[keyword`minLength`]))]));
}
Expand All @@ -568,35 +568,35 @@ function build({
}

// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.4
if (schema[keyword`maxItems`]) {
if (schema[keyword`maxItems`] !== undefined) {
// console.log('maxItems!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`maximum number of items`)), text(': '), text(i18n`the maximum number of items for this array is: `), inlineCode(String(schema[keyword`maxItems`]))]));
}
if (schema[keyword`minItems`]) {
if (schema[keyword`minItems`] !== undefined) {
// console.log('minItems!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`minimum number of items`)), text(': '), text(i18n`the minimum number of items for this array is: `), inlineCode(String(schema[keyword`minItems`]))]));
}
if (schema[keyword`uniqueItems`]) {
// console.log('uniqueItems!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`unique items`)), text(': '), text(i18n`all items in this array must be unique. Duplicates are not allowed.`)]));
}
if (schema[keyword`minContains`] && schema[keyword`contains`]) {
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 ${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`])))]));
}
if (schema[keyword`maxContains`] && schema[keyword`contains`]) {
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 ${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`])))]));
}

// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.5
if (schema[keyword`maxProperties`]) {
if (schema[keyword`maxProperties`] !== undefined) {
// console.log('maxProperties!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`maximum number of properties`)), text(': '), text(i18n`the maximum number of properties for this object is: `), inlineCode(String(schema[keyword`maxProperties`]))]));
}
if (schema[keyword`minProperties`]) {
if (schema[keyword`minProperties`] !== undefined) {
// console.log('minProperties!', schema[s.filename], schema[s.pointer]);
constraints.push(paragraph([strong(text(i18n`minimum number of properties`)), text(': '), text(i18n`the minimum number of properties for this object is: `), inlineCode(String(schema[keyword`minProperties`]))]));
}
Expand Down
2 changes: 2 additions & 0 deletions test/markdownBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ describe('Testing Markdown Builder: stringformats', () => {

it('Simple Types Schema looks OK', () => {
assertMarkdown(results.simpletypes)
.contains('maximum (exclusive)')
.contains('minimum (exclusive)')
.fuzzy`### string_pattern Constraints
**pattern**: the string must match the following regular expression: ${null}
Expand Down

0 comments on commit 2e057fd

Please sign in to comment.