Skip to content

Commit

Permalink
test(schema): test for writing cyclic schemas without an endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Jan 8, 2020
1 parent 2a6063e commit 1633739
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/cyclicSchemaIntegration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

const path = require('path');
const fs = require('fs-extra');
const assert = require('assert');
const { loader } = require('../lib/schemaProxy');
const { assertMarkdown } = require('./testUtils');
const readme = require('../lib/readmeBuilder');
const markdown = require('../lib/markdownBuilder');
const traverse = require('../lib/traverseSchema');
const { writeSchema } = require('../lib/writeSchema');

describe('Integration Test: Cyclic References', () => {
let one;
Expand Down Expand Up @@ -68,4 +70,18 @@ describe('Integration Test: Cyclic References', () => {
assertMarkdown(documents.one)
.contains('one-properties-children-items');
});

it('Schemas with cyclic references get written to disk', () => {
const writer = writeSchema({ origindir: path.resolve(__dirname, 'fixtures', 'cyclic'), schemadir: path.resolve(__dirname, 'fixtures', 'cyclic-out') });
writer(allschemas);
const schemaone = fs.readJsonSync(path.resolve(__dirname, 'fixtures', 'cyclic-out', 'one.schema.json'));
assert.deepStrictEqual(schemaone, {
$schema: 'http://json-schema.org/draft-04/schema#',
$id: 'http://example.com/schemas/one',
type: 'object',
description: 'The first schema in the cycle (or is it the last?)',
examples: [{}],
properties: { children: { type: 'array', items: { anyOf: [{ $ref: 'http://example.com/schemas/three' }, { $ref: 'http://example.com/schemas/two' }] } } },
});
});
});
1 change: 1 addition & 0 deletions test/fixtures/cyclic/one.description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The first schema in the cycle (or is it the last?)
1 change: 1 addition & 0 deletions test/fixtures/cyclic/one.example.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 1633739

Please sign in to comment.