1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const path = require('path');
|
15 | const fs = require('fs-extra');
|
16 | const assert = require('assert');
|
17 | const { loader } = require('../lib/schemaProxy');
|
18 | const { assertMarkdown } = require('./testUtils');
|
19 | const readme = require('../lib/readmeBuilder');
|
20 | const markdown = require('../lib/markdownBuilder');
|
21 | const traverse = require('../lib/traverseSchema');
|
22 | const { writeSchema } = require('../lib/writeSchema');
|
23 |
|
24 | describe('Integration Test: Cyclic References', () => {
|
25 | let one;
|
26 | let two;
|
27 | let three;
|
28 |
|
29 | let proxiedone;
|
30 | let proxiedtwo;
|
31 | let proxiedthree;
|
32 |
|
33 | let allschemas;
|
34 |
|
35 | beforeEach('Read Schemas from disk', async () => {
|
36 | console.log('Reading Schemas');
|
37 | one = await fs.readJson(path.resolve(__dirname, 'fixtures', 'cyclic', 'one.schema.json'));
|
38 | two = await fs.readJson(path.resolve(__dirname, 'fixtures', 'cyclic', 'two.schema.json'));
|
39 | three = await fs.readJson(path.resolve(__dirname, 'fixtures', 'cyclic', 'three.schema.json'));
|
40 |
|
41 | const myloader = loader();
|
42 |
|
43 | console.log('Loading Schemas');
|
44 | proxiedone = myloader(one, path.resolve(__dirname, 'fixtures', 'cyclic', 'one.schema.json'));
|
45 | proxiedtwo = myloader(two, path.resolve(__dirname, 'fixtures', 'cyclic', 'two.schema.json'));
|
46 | proxiedthree = myloader(three, path.resolve(__dirname, 'fixtures', 'cyclic', 'three.schema.json'));
|
47 |
|
48 | console.log('Traversing Schemas');
|
49 |
|
50 | allschemas = traverse([proxiedone, proxiedtwo, proxiedthree]);
|
51 | });
|
52 |
|
53 | it('Schemas with cyclic references generate README', () => {
|
54 | const builder = readme({ readme: true });
|
55 | const result = builder([proxiedone, proxiedtwo, proxiedthree]);
|
56 |
|
57 | assertMarkdown(result)
|
58 | .contains('http://example.com/schemas/one')
|
59 | .contains('http://example.com/schemas/two')
|
60 | .contains('http://example.com/schemas/three')
|
61 | .contains('http://json-schema.org/draft-04/schema#');
|
62 | });
|
63 |
|
64 | it('Schemas with cyclic references generate Markdown', () => {
|
65 | const builder = markdown();
|
66 | const documents = builder(allschemas);
|
67 | assertMarkdown(documents['one-properties-children-items'])
|
68 | .contains('any of');
|
69 |
|
70 | assertMarkdown(documents.one)
|
71 | .contains('one-properties-children-items');
|
72 | });
|
73 |
|
74 | it('Schemas with cyclic references get written to disk', () => {
|
75 | const writer = writeSchema({ origindir: path.resolve(__dirname, 'fixtures', 'cyclic'), schemadir: path.resolve(__dirname, 'fixtures', 'cyclic-out') });
|
76 | writer(allschemas);
|
77 | const schemaone = fs.readJsonSync(path.resolve(__dirname, 'fixtures', 'cyclic-out', 'one.schema.json'));
|
78 | assert.deepStrictEqual(schemaone, {
|
79 | $schema: 'http://json-schema.org/draft-04/schema#',
|
80 | $id: 'http://example.com/schemas/one',
|
81 | type: 'object',
|
82 | description: 'The first schema in the cycle (or is it the last?)',
|
83 | examples: [{}],
|
84 | properties: { children: { type: 'array', items: { anyOf: [{ $ref: 'http://example.com/schemas/three' }, { $ref: 'http://example.com/schemas/two' }] } } },
|
85 | });
|
86 | });
|
87 | });
|