Skip to content

Commit

Permalink
Merge pull request #206 from adobe/type-error-fix
Browse files Browse the repository at this point in the history
Type error tests and fixes
  • Loading branch information
trieloff authored Jan 20, 2020
2 parents 40588ce + 87d709a commit c3cc6db
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 18 deletions.
3 changes: 2 additions & 1 deletion lib/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"the string must be a JSON Pointer, according to ": "the string must be a JSON Pointer, according to ",
"the string must be a URI template, according to ": "the string must be a URI template, according to ",
"the string must be a regular expression, according to ": "the string must be a regular expression, according to ",
"the string must be a relative JSON Pointer, according to ": "the string must be a relative JSON Pointer, according to "
"the string must be a relative JSON Pointer, according to ": "the string must be a relative JSON Pointer, according to ",
"Unknown Type": "Unknown Type"
}
}
3 changes: 3 additions & 0 deletions lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ function build({
}

function type(property) {
if (typeof property[keyword`type`] === 'object') {
return text(i18n`Unknown Type`);
}
const types = Array.isArray(property[keyword`type`]) ? property[keyword`type`] : [property[keyword`type`]];
const realtypes = flist(filter(types, mytype => mytype !== 'null' && mytype !== undefined));
if (property[keyword`allOf`] || property[keyword`anyOf`] || property[keyword`oneOf`] || property[keyword`not`]) {
Expand Down
19 changes: 3 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"nyc": "^14.1.1",
"semantic-release": "^15.13.20",
"unist-util-select": "^3.0.0",
"json-logic-js": "axa-ch/json-logic-js"
"json-logic-js": "git://github.com/axa-ch/cyclic-schemas-test.git#fix/type-key-exception"
},
"engines": {
"node": ">= 10.0.0"
Expand Down
28 changes: 28 additions & 0 deletions test/fixtures/type/button.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "http://www.example.com/schemas/components/Button.json",
"type": "object",
"title": "Button",
"description": "Renders a Button.",
"additionalProperties": false,
"properties": {
"properties": {
"type": "object",
"title": "Properties",
"description": "Properties of Button.",
"additionalProperties": false,
"properties": {
"type": {
"type": "string",
"enum": [
"button",
"submit",
"reset"
],
"title": "Type",
"description": "The type of the Button (not used for anchors)."
}
}
}
}
}
20 changes: 20 additions & 0 deletions test/fixtures/type/type.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "object",
"title": "Properties",
"description": "Properties of Button.",

"additionalProperties": false,
"properties": {
"value": {
"type": "string",
"title": "Value",
"description": "The value of the Button."
},
"type": {
"type": "string",
"enum": ["button", "submit", "reset"],
"title": "Type",
"description": "The type of the Button (not used for anchors)."
}
}
}
22 changes: 22 additions & 0 deletions test/markdownBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ describe('Testing Markdown Builder: title', () => {
});
});

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

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

it('Type Schema looks OK', () => {
assertMarkdown(results.type)
.fuzzy`The type of the Button (not used for anchors).`
.print();
});

it('Button Schema looks OK', () => {
assertMarkdown(results.button)
.fuzzy`## Button Type`
.print();
});
});

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

Expand Down
10 changes: 10 additions & 0 deletions test/readmeBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ describe('Testing Readme Builder', () => {
assert.equal(builder(), null);
});

it('Readme Builder builds a README for type', async () => {
const schemas = await loadschemas('type');
const builder = build({ readme: true });
const result = builder(schemas);

assertMarkdown(result)
.contains('# README')
.print();
});

it('Readme Builder builds a medium README for multiple Schemas', async () => {
const schemas = await loadschemas('readme-1');
const builder = build({ readme: true });
Expand Down

0 comments on commit c3cc6db

Please sign in to comment.