Skip to content

Commit

Permalink
fix(markdown): correcly show type of nullable types in header
Browse files Browse the repository at this point in the history
fixes #237
  • Loading branch information
trieloff committed Jul 31, 2020
1 parent 65a6a77 commit 53c1a0b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function build({
}

function type(property) {
if (typeof property[keyword`type`] === 'object') {
if (!Array.isArray(property[keyword`type`]) && typeof property[keyword`type`] === 'object') {
return text(i18n`Unknown Type`);
}
const types = Array.isArray(property[keyword`type`]) ? property[keyword`type`] : [property[keyword`type`]];
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/nullable/array.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/type-array-repro.json",
"type": "object",
"title": "Type Array Repro",
"description": "Type Array Issue Reproduction",
"required": [
"sampleProp"
],
"additionalProperties": false,
"properties": {
"sampleProp": {
"type": ["string", "null"],
"title": "Sample Property"
}
}
}
15 changes: 15 additions & 0 deletions test/markdownBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ not
});
});

describe('Testing Markdown Builder: nullable', () => {
let results;

before(async () => {
const schemas = await loadschemas('nullable');
const builder = build({ header: false });
results = builder(schemas);
});

it('Nullable Array Type Schema looks OK', () => {
assertMarkdown(results.array)
.fuzzy`| [sampleProp](#sampleProp) | \`string\` | Required | can be null |`;
});
});

describe('Testing Markdown Builder: title', () => {
let results;

Expand Down

0 comments on commit 53c1a0b

Please sign in to comment.