Skip to content

Commit

Permalink
feat: array top level validations (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Jankowski authored Sep 25, 2023
1 parent 58d3566 commit 71c60cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/__fixtures__/arrays/of-complex-objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"type": [
"array"
],
"minItems": 1,
"maxItems": 10,
"items":{
"title": "User",
"type": "object",
Expand Down Expand Up @@ -91,4 +93,4 @@
"required": ["name", "age", "completed_at"]
}

}
}
10 changes: 9 additions & 1 deletion src/components/SchemaRow/TopLevelSchemaRow.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { isRegularNode, RegularNode } from '@stoplight/json-schema-tree';
import { Box, Flex, HStack, Icon, Menu, Pressable } from '@stoplight/mosaic';
import { useUpdateAtom } from 'jotai/utils';
import { isEmpty } from 'lodash';
import * as React from 'react';

import { COMBINER_NAME_MAP } from '../../consts';
import { useIsOnScreen } from '../../hooks/useIsOnScreen';
import { calculateChildrenToShow, isComplexArray } from '../../tree';
import { showPathCrumbsAtom } from '../PathCrumbs/state';
import { Description } from '../shared';
import { Description, getValidationsFromSchema, Validations } from '../shared';
import { ChildStack } from '../shared/ChildStack';
import { Error } from '../shared/Error';
import { SchemaRow, SchemaRowProps } from './SchemaRow';
Expand Down Expand Up @@ -92,6 +93,7 @@ export const TopLevelSchemaRow = ({
}

if (isComplexArray(schemaNode) && isPureObjectNode(schemaNode.children[0])) {
const validations = getValidationsFromSchema(schemaNode);
return (
<>
<ScrollCheck />
Expand All @@ -101,6 +103,12 @@ export const TopLevelSchemaRow = ({
array of:
</Box>

{!isEmpty(validations) && (
<Box fontSize="sm" mb={1} mt={-2}>
<Validations validations={isRegularNode(schemaNode) ? getValidationsFromSchema(schemaNode) : {}} />
</Box>
)}

{childNodes.length > 0 ? (
<ChildStack
schemaNode={schemaNode}
Expand Down

0 comments on commit 71c60cb

Please sign in to comment.