Skip to content

Commit 71c60cb

Browse files
author
Jakub Jankowski
authored
feat: array top level validations (#237)
1 parent 58d3566 commit 71c60cb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/__fixtures__/arrays/of-complex-objects.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"type": [
33
"array"
44
],
5+
"minItems": 1,
6+
"maxItems": 10,
57
"items":{
68
"title": "User",
79
"type": "object",
@@ -91,4 +93,4 @@
9193
"required": ["name", "age", "completed_at"]
9294
}
9395

94-
}
96+
}

src/components/SchemaRow/TopLevelSchemaRow.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { isRegularNode, RegularNode } from '@stoplight/json-schema-tree';
22
import { Box, Flex, HStack, Icon, Menu, Pressable } from '@stoplight/mosaic';
33
import { useUpdateAtom } from 'jotai/utils';
4+
import { isEmpty } from 'lodash';
45
import * as React from 'react';
56

67
import { COMBINER_NAME_MAP } from '../../consts';
78
import { useIsOnScreen } from '../../hooks/useIsOnScreen';
89
import { calculateChildrenToShow, isComplexArray } from '../../tree';
910
import { showPathCrumbsAtom } from '../PathCrumbs/state';
10-
import { Description } from '../shared';
11+
import { Description, getValidationsFromSchema, Validations } from '../shared';
1112
import { ChildStack } from '../shared/ChildStack';
1213
import { Error } from '../shared/Error';
1314
import { SchemaRow, SchemaRowProps } from './SchemaRow';
@@ -92,6 +93,7 @@ export const TopLevelSchemaRow = ({
9293
}
9394

9495
if (isComplexArray(schemaNode) && isPureObjectNode(schemaNode.children[0])) {
96+
const validations = getValidationsFromSchema(schemaNode);
9597
return (
9698
<>
9799
<ScrollCheck />
@@ -101,6 +103,12 @@ export const TopLevelSchemaRow = ({
101103
array of:
102104
</Box>
103105

106+
{!isEmpty(validations) && (
107+
<Box fontSize="sm" mb={1} mt={-2}>
108+
<Validations validations={isRegularNode(schemaNode) ? getValidationsFromSchema(schemaNode) : {}} />
109+
</Box>
110+
)}
111+
104112
{childNodes.length > 0 ? (
105113
<ChildStack
106114
schemaNode={schemaNode}

0 commit comments

Comments
 (0)