Skip to content

Commit 5304cb4

Browse files
authored
fix: use items validation for flattened arrays (#129)
* fix: use items validation for flattened arrays * style: const name
1 parent 06ed0c6 commit 5304cb4

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/__tests__/__snapshots__/index.spec.tsx.snap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,11 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
26582658
<div>availableDeliveryTypes</div>
26592659
<span class=\\"text-green-6 dark:text-green-4\\">array[string]</span>
26602660
</div>
2661-
<div></div>
2661+
<span class=\\"bp3-popover-wrapper\\">
2662+
<span class=\\"bp3-popover-target\\">
2663+
<div><span class=\\"text-darken-7 dark:text-lighten-6\\">+1</span></div>
2664+
</span>
2665+
</span>
26622666
</div>
26632667
</div>
26642668
</div>
@@ -2669,7 +2673,11 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
26692673
<div>ticketRecipients</div>
26702674
<span class=\\"text-green-6 dark:text-green-4\\">array[string]</span>
26712675
</div>
2672-
<div></div>
2676+
<span class=\\"bp3-popover-wrapper\\">
2677+
<span class=\\"bp3-popover-target\\">
2678+
<div><span class=\\"text-darken-7 dark:text-lighten-6\\">+1</span></div>
2679+
</span>
2680+
</span>
26732681
</div>
26742682
</div>
26752683
</div>

src/tree/utils/walk.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,24 @@ export function* processNode(node: JSONSchema4): IterableIterator<SchemaNode> {
4949
yield combinerNode;
5050
}
5151
} else if (type) {
52+
const primaryType = getPrimaryType(node);
53+
let validationNode: JSONSchema4 = node;
54+
if (
55+
primaryType === SchemaKind.Array &&
56+
_isObject(node.items) &&
57+
!Array.isArray(node.items) &&
58+
getCombiners(node.items) === void 0
59+
) {
60+
const validationNodePrimaryType = getPrimaryType(node.items);
61+
if (validationNodePrimaryType !== SchemaKind.Array && validationNodePrimaryType !== SchemaKind.Object) {
62+
validationNode = node.items;
63+
}
64+
}
65+
5266
const base: IBaseNode = {
5367
id: generateId(),
5468
type: flattenTypes(type),
55-
validations: getValidations(node),
69+
validations: getValidations(validationNode),
5670
annotations: getAnnotations(node),
5771
...('required' in node && { required: normalizeRequired(node.required) }),
5872
enum: node.enum,

0 commit comments

Comments
 (0)