docusaurus-plugin-generate-schema-docs 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -6
- package/__tests__/ExampleDataLayer.test.js +78 -155
- package/__tests__/__fixtures__/static/schemas/add-to-cart-event.json +4 -15
- package/__tests__/__fixtures__/static/schemas/choice-event.json +72 -0
- package/__tests__/__fixtures__/static/schemas/components/dataLayer.json +52 -54
- package/__tests__/__fixtures__/static/schemas/components/product.json +124 -210
- package/__tests__/__fixtures__/static/schemas/nested/child-event.json +10 -0
- package/__tests__/__fixtures__/static/schemas/nested/grandchild-a.json +9 -0
- package/__tests__/__fixtures__/static/schemas/nested/grandchild-b.json +9 -0
- package/__tests__/__fixtures__/static/schemas/nested/parent-event.json +7 -0
- package/__tests__/__fixtures__/static/schemas/root-any-of-event.json +34 -0
- package/__tests__/__fixtures__/static/schemas/root-choice-event.json +36 -0
- package/__tests__/__fixtures__/validateSchemas/circular-schema.json +6 -6
- package/__tests__/__fixtures__/validateSchemas/components/referenced.json +9 -7
- package/__tests__/__fixtures__/validateSchemas/invalid-example-schema.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/main-schema-with-missing-ref.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/main-schema-with-ref.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/no-example-schema.json +11 -11
- package/__tests__/__fixtures__/validateSchemas/schema-A.json +5 -5
- package/__tests__/__fixtures__/validateSchemas/schema-B.json +5 -5
- package/__tests__/__fixtures__/validateSchemas/valid-schema.json +7 -7
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/add-to-cart-event.json +44 -0
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/components/dataLayer.json +56 -0
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/components/product.json +125 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/add-to-cart-event.json +44 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/components/dataLayer.json +56 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/components/product.json +125 -0
- package/__tests__/__fixtures_versioned__/versions.json +1 -0
- package/__tests__/__snapshots__/ExampleDataLayer.test.js.snap +117 -0
- package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +92 -0
- package/__tests__/__snapshots__/generateEventDocs.test.js.snap +113 -15
- package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +53 -0
- package/__tests__/components/FoldableRows.test.js +330 -0
- package/__tests__/components/PropertiesTable.test.js +31 -14
- package/__tests__/components/PropertyRow.test.js +471 -51
- package/__tests__/components/SchemaJsonViewer.test.js +23 -19
- package/__tests__/components/SchemaRows.test.js +96 -66
- package/__tests__/components/SchemaViewer.test.js +34 -17
- package/__tests__/components/TableHeader.test.js +12 -12
- package/__tests__/generateEventDocs.nested.test.js +80 -0
- package/__tests__/generateEventDocs.test.js +77 -71
- package/__tests__/generateEventDocs.versioned.test.js +69 -0
- package/__tests__/helpers/buildExampleFromSchema.test.js +160 -160
- package/__tests__/helpers/file-system.test.js +44 -0
- package/__tests__/helpers/getConstraints.test.js +48 -48
- package/__tests__/helpers/loadSchema.test.js +11 -5
- package/__tests__/helpers/path-helpers.test.js +34 -0
- package/__tests__/helpers/processSchema.test.js +42 -22
- package/__tests__/helpers/schema-processing.test.js +82 -0
- package/__tests__/helpers/schemaToExamples.test.js +56 -0
- package/__tests__/helpers/schemaToTableData.filtering.test.js +65 -0
- package/__tests__/helpers/schemaToTableData.hierarchicalLines.test.js +539 -0
- package/__tests__/helpers/schemaToTableData.test.js +222 -0
- package/__tests__/helpers/update-schema-ids.test.js +107 -0
- package/__tests__/update-schema-ids.test.js +39 -0
- package/__tests__/validateSchemas.test.js +125 -88
- package/components/ExampleDataLayer.js +59 -28
- package/components/FoldableRows.js +164 -0
- package/components/PropertiesTable.js +10 -7
- package/components/PropertyRow.js +169 -60
- package/components/SchemaJsonViewer.js +6 -6
- package/components/SchemaRows.css +236 -14
- package/components/SchemaRows.js +24 -41
- package/components/SchemaViewer.js +19 -13
- package/components/TableHeader.js +12 -12
- package/generateEventDocs.js +141 -61
- package/helpers/buildExampleFromSchema.js +58 -72
- package/helpers/choice-index-template.js +22 -0
- package/helpers/file-system.js +32 -0
- package/helpers/getConstraints.js +43 -44
- package/helpers/loadSchema.js +2 -2
- package/helpers/path-helpers.js +22 -0
- package/helpers/processSchema.js +19 -19
- package/helpers/{mdx-template.js → schema-doc-template.js} +12 -12
- package/helpers/schema-processing.js +75 -0
- package/helpers/schemaToExamples.js +99 -0
- package/helpers/schemaToTableData.js +311 -0
- package/helpers/update-schema-ids.js +47 -0
- package/index.js +143 -54
- package/package.json +1 -1
- package/validateSchemas.js +54 -71
|
@@ -1,188 +1,188 @@
|
|
|
1
1
|
import buildExampleFromSchema from '../../helpers/buildExampleFromSchema.js';
|
|
2
2
|
|
|
3
3
|
describe('buildExampleFromSchema', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
it('should build a basic example from a schema', () => {
|
|
5
|
+
const schema = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
name: { type: 'string' },
|
|
9
|
+
age: { type: 'integer' },
|
|
10
|
+
isStudent: { type: 'boolean' },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const example = buildExampleFromSchema(schema);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
16
|
+
expect(example).toEqual({
|
|
17
|
+
name: '',
|
|
18
|
+
age: 0,
|
|
19
|
+
isStudent: false,
|
|
21
20
|
});
|
|
21
|
+
});
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
it('should handle nested objects and arrays', () => {
|
|
24
|
+
const schema = {
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
user: {
|
|
28
|
+
type: 'object',
|
|
29
|
+
properties: {
|
|
30
|
+
name: { type: 'string' },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
posts: {
|
|
34
|
+
type: 'array',
|
|
35
|
+
items: {
|
|
25
36
|
type: 'object',
|
|
26
37
|
properties: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
posts: {
|
|
34
|
-
type: 'array',
|
|
35
|
-
items: {
|
|
36
|
-
type: 'object',
|
|
37
|
-
properties: {
|
|
38
|
-
title: { type: 'string' },
|
|
39
|
-
tags: {
|
|
40
|
-
type: 'array',
|
|
41
|
-
items: { type: 'string' },
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
38
|
+
title: { type: 'string' },
|
|
39
|
+
tags: {
|
|
40
|
+
type: 'array',
|
|
41
|
+
items: { type: 'string' },
|
|
42
|
+
},
|
|
46
43
|
},
|
|
47
|
-
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
const example = buildExampleFromSchema(schema);
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
51
|
+
expect(example).toEqual({
|
|
52
|
+
user: {
|
|
53
|
+
name: '',
|
|
54
|
+
},
|
|
55
|
+
posts: [
|
|
56
|
+
{
|
|
57
|
+
title: '',
|
|
58
|
+
tags: [''],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
62
61
|
});
|
|
62
|
+
});
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
it('should use examples, const, and default values', () => {
|
|
65
|
+
const schema = {
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties: {
|
|
68
|
+
name: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
examples: ['John Doe'],
|
|
71
|
+
},
|
|
72
|
+
role: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
const: 'admin',
|
|
75
|
+
},
|
|
76
|
+
level: {
|
|
77
|
+
type: 'integer',
|
|
78
|
+
default: 1,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
const example = buildExampleFromSchema(schema);
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
85
|
+
expect(example).toEqual({
|
|
86
|
+
name: 'John Doe',
|
|
87
|
+
role: 'admin',
|
|
88
|
+
level: 1,
|
|
90
89
|
});
|
|
90
|
+
});
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
},
|
|
92
|
+
it('should build a complex example', () => {
|
|
93
|
+
const schema = {
|
|
94
|
+
type: 'object',
|
|
95
|
+
properties: {
|
|
96
|
+
event: {
|
|
97
|
+
type: 'string',
|
|
98
|
+
examples: ['purchase'],
|
|
99
|
+
},
|
|
100
|
+
ecommerce: {
|
|
101
|
+
type: 'object',
|
|
102
|
+
properties: {
|
|
103
|
+
transaction_id: {
|
|
104
|
+
type: 'string',
|
|
105
|
+
examples: ['T_12345'],
|
|
106
|
+
},
|
|
107
|
+
value: {
|
|
108
|
+
type: 'number',
|
|
109
|
+
default: 10.0,
|
|
110
|
+
},
|
|
111
|
+
items: {
|
|
112
|
+
type: 'array',
|
|
113
|
+
items: {
|
|
114
|
+
type: 'object',
|
|
115
|
+
properties: {
|
|
116
|
+
item_id: { type: 'string', examples: ['SKU_123'] },
|
|
117
|
+
item_name: { type: 'string', examples: ['Stan Smith Shoes'] },
|
|
118
|
+
price: { type: 'number' },
|
|
119
|
+
quantity: { type: 'integer', default: 1 },
|
|
124
120
|
},
|
|
121
|
+
},
|
|
125
122
|
},
|
|
126
|
-
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
const example = buildExampleFromSchema(schema);
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
130
|
+
expect(example).toEqual({
|
|
131
|
+
event: 'purchase',
|
|
132
|
+
ecommerce: {
|
|
133
|
+
transaction_id: 'T_12345',
|
|
134
|
+
value: 10.0,
|
|
135
|
+
items: [
|
|
136
|
+
{
|
|
137
|
+
item_id: 'SKU_123',
|
|
138
|
+
item_name: 'Stan Smith Shoes',
|
|
139
|
+
price: 0,
|
|
140
|
+
quantity: 1,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
145
144
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
});
|
|
146
|
+
it('should not include empty objects for properties with no defined value', () => {
|
|
147
|
+
const schema = {
|
|
148
|
+
type: 'object',
|
|
149
|
+
properties: {
|
|
150
|
+
event: { type: 'string', examples: ['test_event'] },
|
|
151
|
+
user_data: {
|
|
152
|
+
type: 'object',
|
|
153
|
+
},
|
|
154
|
+
ecommerce: {
|
|
155
|
+
type: 'object',
|
|
156
|
+
properties: {
|
|
157
|
+
items: {
|
|
158
|
+
type: 'array',
|
|
159
|
+
items: {
|
|
160
|
+
type: 'object',
|
|
161
|
+
properties: {
|
|
162
|
+
item_id: { type: 'string', examples: ['SKU_123'] },
|
|
153
163
|
},
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
empty_object: {
|
|
169
|
-
type: 'object',
|
|
170
|
-
properties: {}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
};
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
empty_object: {
|
|
169
|
+
type: 'object',
|
|
170
|
+
properties: {},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
const example = buildExampleFromSchema(schema);
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
});
|
|
177
|
+
expect(example).toEqual({
|
|
178
|
+
event: 'test_event',
|
|
179
|
+
ecommerce: {
|
|
180
|
+
items: [
|
|
181
|
+
{
|
|
182
|
+
item_id: 'SKU_123',
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
},
|
|
187
186
|
});
|
|
187
|
+
});
|
|
188
188
|
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { readSchemas, writeDoc, createDir } from '../../helpers/file-system';
|
|
4
|
+
|
|
5
|
+
jest.mock('fs', () => {
|
|
6
|
+
const memfs = require('memfs');
|
|
7
|
+
return memfs;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('file-system helpers', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
fs.vol.reset();
|
|
13
|
+
fs.vol.fromJSON({
|
|
14
|
+
'/schemas/schema1.json': '{}',
|
|
15
|
+
'/schemas/schema2.json': '{}',
|
|
16
|
+
'/schemas/not-a-schema.txt': 'hello',
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('readSchemas', () => {
|
|
21
|
+
it('should read all json files from a directory', () => {
|
|
22
|
+
const schemas = readSchemas('/schemas');
|
|
23
|
+
expect(schemas).toHaveLength(2);
|
|
24
|
+
expect(schemas[0].fileName).toBe('schema1.json');
|
|
25
|
+
expect(schemas[1].fileName).toBe('schema2.json');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('writeDoc', () => {
|
|
30
|
+
it('should write a file to the specified directory', () => {
|
|
31
|
+
fs.mkdirSync('/output', { recursive: true });
|
|
32
|
+
writeDoc('/output', 'doc1.mdx', 'content');
|
|
33
|
+
const content = fs.readFileSync('/output/doc1.mdx', 'utf-8');
|
|
34
|
+
expect(content).toBe('content');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('createDir', () => {
|
|
39
|
+
it('should create a directory if it does not exist', () => {
|
|
40
|
+
createDir('/new-dir');
|
|
41
|
+
expect(fs.existsSync('/new-dir')).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
import { getConstraints } from '../../helpers/getConstraints';
|
|
2
2
|
|
|
3
3
|
describe('getConstraints', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
it('should return "required" if isReq is true', () => {
|
|
5
|
+
const constraints = getConstraints({}, true);
|
|
6
|
+
expect(constraints).toContain('required');
|
|
7
|
+
});
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
it('should handle simple key-value constraints', () => {
|
|
10
|
+
const prop = {
|
|
11
|
+
minLength: 1,
|
|
12
|
+
maxLength: 10,
|
|
13
|
+
minimum: 0,
|
|
14
|
+
maximum: 100,
|
|
15
|
+
minItems: 1,
|
|
16
|
+
maxItems: 5,
|
|
17
|
+
};
|
|
18
|
+
const constraints = getConstraints(prop, false);
|
|
19
|
+
expect(constraints).toEqual([
|
|
20
|
+
'minLength: 1',
|
|
21
|
+
'maxLength: 10',
|
|
22
|
+
'minimum: 0',
|
|
23
|
+
'maximum: 100',
|
|
24
|
+
'minItems: 1',
|
|
25
|
+
'maxItems: 5',
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
it('should handle pattern constraint', () => {
|
|
30
|
+
const prop = { pattern: '^[a-z]+$' };
|
|
31
|
+
const constraints = getConstraints(prop, false);
|
|
32
|
+
expect(constraints).toContain('pattern: /^[a-z]+$/');
|
|
33
|
+
});
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
it('should handle uniqueItems constraint', () => {
|
|
36
|
+
const prop = { uniqueItems: true };
|
|
37
|
+
const constraints = getConstraints(prop, false);
|
|
38
|
+
expect(constraints).toContain('uniqueItems: true');
|
|
39
|
+
});
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
it('should handle additionalProperties constraint', () => {
|
|
42
|
+
const prop = { additionalProperties: false };
|
|
43
|
+
const constraints = getConstraints(prop, false);
|
|
44
|
+
expect(constraints).toContain('additionalProperties: false');
|
|
45
|
+
});
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
it('should handle enum constraint', () => {
|
|
48
|
+
const prop = { enum: ['a', 'b', 'c'] };
|
|
49
|
+
const constraints = getConstraints(prop, false);
|
|
50
|
+
expect(constraints).toContain('enum: [a, b, c]');
|
|
51
|
+
});
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
it('should handle const constraint', () => {
|
|
54
|
+
const prop = { const: 'a' };
|
|
55
|
+
const constraints = getConstraints(prop, false);
|
|
56
|
+
expect(constraints).toContain('const: "a"');
|
|
57
|
+
});
|
|
58
58
|
});
|
|
@@ -6,9 +6,15 @@ import path from 'path';
|
|
|
6
6
|
import loadSchema from '../../helpers/loadSchema';
|
|
7
7
|
|
|
8
8
|
describe('loadSchema', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
it('should load and parse a JSON file', () => {
|
|
10
|
+
const filePath = path.join(
|
|
11
|
+
__dirname,
|
|
12
|
+
'..',
|
|
13
|
+
'__fixtures__',
|
|
14
|
+
'validateSchemas',
|
|
15
|
+
'circular-schema.json',
|
|
16
|
+
);
|
|
17
|
+
const schema = loadSchema(filePath);
|
|
18
|
+
expect(schema.title).toBe('Circular Schema');
|
|
19
|
+
});
|
|
14
20
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getPathsForVersion } from '../../helpers/path-helpers';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
describe('getPathsForVersion', () => {
|
|
5
|
+
const siteDir = '/test/site';
|
|
6
|
+
|
|
7
|
+
it('should return paths for a specific version', () => {
|
|
8
|
+
const version = '1.0.0';
|
|
9
|
+
const { schemaDir, outputDir } = getPathsForVersion(version, siteDir);
|
|
10
|
+
expect(schemaDir).toBe(path.join(siteDir, 'static/schemas', version));
|
|
11
|
+
expect(outputDir).toBe(
|
|
12
|
+
path.join(siteDir, 'versioned_docs', `version-${version}`),
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return paths for the "current" version', () => {
|
|
17
|
+
const version = 'current';
|
|
18
|
+
const { schemaDir, outputDir } = getPathsForVersion(version, siteDir);
|
|
19
|
+
expect(schemaDir).toBe(path.join(siteDir, 'static/schemas', 'next'));
|
|
20
|
+
expect(outputDir).toBe(path.join(siteDir, 'docs'));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should return paths for a non-versioned site', () => {
|
|
24
|
+
const { schemaDir, outputDir } = getPathsForVersion(null, siteDir);
|
|
25
|
+
expect(schemaDir).toBe(path.join(siteDir, 'static/schemas'));
|
|
26
|
+
expect(outputDir).toBe(path.join(siteDir, 'docs'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should handle undefined version', () => {
|
|
30
|
+
const { schemaDir, outputDir } = getPathsForVersion(undefined, siteDir);
|
|
31
|
+
expect(schemaDir).toBe(path.join(siteDir, 'static/schemas'));
|
|
32
|
+
expect(outputDir).toBe(path.join(siteDir, 'docs'));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -6,31 +6,51 @@ import path from 'path';
|
|
|
6
6
|
import processSchema from '../../helpers/processSchema';
|
|
7
7
|
|
|
8
8
|
describe('processSchema', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
it('should bundle refs and return a merged schema', async () => {
|
|
10
|
+
const filePath = path.join(
|
|
11
|
+
__dirname,
|
|
12
|
+
'..',
|
|
13
|
+
'__fixtures__',
|
|
14
|
+
'validateSchemas',
|
|
15
|
+
'main-schema-with-ref.json',
|
|
16
|
+
);
|
|
17
|
+
const mergedSchema = await processSchema(filePath);
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
expect(mergedSchema.title).toBe('Main Schema with Ref');
|
|
20
|
+
expect(mergedSchema.properties.component.$ref).toBeUndefined();
|
|
21
|
+
expect(mergedSchema.properties.component.type).toBe('object');
|
|
22
|
+
expect(mergedSchema.properties.component.properties.prop.type).toBe(
|
|
23
|
+
'string',
|
|
24
|
+
);
|
|
25
|
+
});
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
it('should handle circular references correctly', async () => {
|
|
28
|
+
const filePath = path.join(
|
|
29
|
+
__dirname,
|
|
30
|
+
'..',
|
|
31
|
+
'__fixtures__',
|
|
32
|
+
'validateSchemas',
|
|
33
|
+
'circular-schema.json',
|
|
34
|
+
);
|
|
35
|
+
const mergedSchema = await processSchema(filePath);
|
|
22
36
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
expect(mergedSchema.title).toBe('Circular Schema');
|
|
38
|
+
expect(mergedSchema.properties.parent.$ref).toBe('#');
|
|
39
|
+
});
|
|
26
40
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
it('should handle multi-file circular references and produce a self-contained schema', async () => {
|
|
42
|
+
const filePath = path.join(
|
|
43
|
+
__dirname,
|
|
44
|
+
'..',
|
|
45
|
+
'__fixtures__',
|
|
46
|
+
'validateSchemas',
|
|
47
|
+
'schema-A.json',
|
|
48
|
+
);
|
|
49
|
+
const mergedSchema = await processSchema(filePath);
|
|
30
50
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
51
|
+
expect(mergedSchema.title).toBe('Schema A');
|
|
52
|
+
expect(mergedSchema.properties.b.$ref).toBeUndefined();
|
|
53
|
+
expect(mergedSchema.properties.b.title).toBe('Schema B');
|
|
54
|
+
expect(mergedSchema.properties.b.properties.a.$ref).toBe('#');
|
|
55
|
+
});
|
|
36
56
|
});
|