Skip to content

Commit f6892e2

Browse files
committed
fix: process combiners placed under arrays
1 parent 5327ee3 commit f6892e2

File tree

4 files changed

+175
-3
lines changed

4 files changed

+175
-3
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"type": "array",
3+
"items": {
4+
"title": "Todo Full",
5+
"allOf": [
6+
{
7+
"title": "Todo Partial",
8+
"type": "object",
9+
"properties": {
10+
"name": {
11+
"type": "string"
12+
},
13+
"completed": {
14+
"type": [
15+
"boolean",
16+
"null"
17+
]
18+
}
19+
},
20+
"required": [
21+
"name",
22+
"completed"
23+
],
24+
"x-tags": [
25+
"Todos"
26+
]
27+
},
28+
{
29+
"type": "object",
30+
"properties": {
31+
"id": {
32+
"type": "integer",
33+
"minimum": 0,
34+
"maximum": 1000000
35+
},
36+
"completed_at": {
37+
"type": [
38+
"string",
39+
"null"
40+
],
41+
"format": "date-time"
42+
},
43+
"created_at": {
44+
"type": "string",
45+
"format": "date-time"
46+
},
47+
"updated_at": {
48+
"type": "string",
49+
"format": "date-time"
50+
},
51+
"user": {
52+
"title": "User",
53+
"type": "object",
54+
"properties": {
55+
"name": {
56+
"type": "string",
57+
"description": "The user's full name."
58+
},
59+
"age": {
60+
"type": "number",
61+
"minimum": 0,
62+
"maximum": 150
63+
}
64+
},
65+
"required": [
66+
"name",
67+
"age"
68+
],
69+
"x-tags": [
70+
"Todos"
71+
]
72+
}
73+
},
74+
"required": [
75+
"id",
76+
"user"
77+
]
78+
}
79+
],
80+
"x-tags": [
81+
"Todos"
82+
]
83+
}
84+
}

src/tree/__tests__/__snapshots__/populateTree.spec.ts.snap

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,88 @@ Object {
359359
"parent": null,
360360
}
361361
`;
362+
363+
exports[`populateTree util should match todo-allof.schema.json 1`] = `
364+
Object {
365+
"children": Array [
366+
Object {
367+
"children": Array [
368+
Object {
369+
"children": Array [
370+
Object {
371+
"children": Array [
372+
Object {
373+
"id": "random-id",
374+
"name": "",
375+
"parent": [Circular],
376+
},
377+
Object {
378+
"id": "random-id",
379+
"name": "",
380+
"parent": [Circular],
381+
},
382+
],
383+
"id": "random-id",
384+
"name": "",
385+
"parent": [Circular],
386+
},
387+
Object {
388+
"children": Array [
389+
Object {
390+
"id": "random-id",
391+
"name": "",
392+
"parent": [Circular],
393+
},
394+
Object {
395+
"id": "random-id",
396+
"name": "",
397+
"parent": [Circular],
398+
},
399+
Object {
400+
"id": "random-id",
401+
"name": "",
402+
"parent": [Circular],
403+
},
404+
Object {
405+
"id": "random-id",
406+
"name": "",
407+
"parent": [Circular],
408+
},
409+
Object {
410+
"children": Array [
411+
Object {
412+
"id": "random-id",
413+
"name": "",
414+
"parent": [Circular],
415+
},
416+
Object {
417+
"id": "random-id",
418+
"name": "",
419+
"parent": [Circular],
420+
},
421+
],
422+
"id": "random-id",
423+
"name": "",
424+
"parent": [Circular],
425+
},
426+
],
427+
"id": "random-id",
428+
"name": "",
429+
"parent": [Circular],
430+
},
431+
],
432+
"id": "random-id",
433+
"name": "",
434+
"parent": [Circular],
435+
},
436+
],
437+
"id": "random-id",
438+
"name": "",
439+
"parent": [Circular],
440+
},
441+
],
442+
"id": "random-id",
443+
"name": "",
444+
"parent": null,
445+
}
446+
`;

src/tree/__tests__/populateTree.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('populateTree util', () => {
1818
'array-of-objects.json',
1919
'array-of-refs.json',
2020
'array-of-allofs.json',
21+
'todo-allof.schema.json',
2122
'tickets.schema.json',
2223
])('should match %s', filename => {
2324
const schema = JSON.parse(fs.readFileSync(path.resolve(BASE_PATH, filename), 'utf8'));

src/tree/populateTree.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { JSONSchema4 } from 'json-schema';
55
import { isObject as _isObject } from 'lodash';
66
import { IArrayNode, IObjectNode, SchemaKind, SchemaNode, SchemaTreeListNode } from '../types';
77
import { mergeAllOf } from '../utils';
8+
import { getCombiner } from '../utils/getCombiner';
89
import { getPrimaryType } from '../utils/getPrimaryType';
910
import { isCombinerNode, isRefNode } from '../utils/guards';
10-
import { isCombiner } from '../utils/isCombiner';
1111
import { metadataStore } from './metadata';
1212
import { walk } from './walk';
1313

@@ -106,8 +106,10 @@ function processArray(
106106
case SchemaKind.Array:
107107
return processArray(node, schema.items as IObjectNode, level, [...path, 'items'], options);
108108
default:
109-
if (typeof subtype === 'string' && isCombiner(subtype)) {
110-
return processArray(node, schema.items as IObjectNode, level, [...path, 'items'], options);
109+
const combiner = getCombiner(schema.items);
110+
if (combiner) {
111+
(node as TreeListParentNode).children = [];
112+
populateTree(schema.items, node as TreeListParentNode, level, [...path, 'items'], options);
111113
}
112114
}
113115
}

0 commit comments

Comments
 (0)