Skip to content

Commit c467ab1

Browse files
author
Daniel A. White
authored
feat: pass maxRefDepth to tree to limit recursion (#243)
1 parent 38f4f92 commit c467ab1

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"dependencies": {
4848
"@stoplight/json": "^3.20.1",
49-
"@stoplight/json-schema-tree": "^2.2.5",
49+
"@stoplight/json-schema-tree": "^2.3.0",
5050
"@stoplight/react-error-boundary": "^2.0.0",
5151
"@types/json-schema": "^7.0.7",
5252
"classnames": "^2.2.6",

src/components/JsonSchemaViewer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export type JsonSchemaProps = Partial<JSVOptions> & {
2323
emptyText?: string;
2424
className?: string;
2525
resolveRef?: SchemaTreeRefDereferenceFn;
26+
/** Controls the level of recursion of refs. Prevents overly complex trees and running out of stack depth. */
27+
maxRefDepth?: number;
2628
onTreePopulated?: (props: { rootNode: RootNode; nodeCount: number }) => void;
2729
maxHeight?: number;
2830
parentCrumbs?: string[];
@@ -80,6 +82,7 @@ const JsonSchemaViewerInner = ({
8082
viewMode,
8183
className,
8284
resolveRef,
85+
maxRefDepth,
8386
emptyText = 'No schema defined',
8487
onTreePopulated,
8588
maxHeight,
@@ -91,6 +94,7 @@ const JsonSchemaViewerInner = ({
9194
| 'viewMode'
9295
| 'className'
9396
| 'resolveRef'
97+
| 'maxRefDepth'
9498
| 'emptyText'
9599
| 'onTreePopulated'
96100
| 'maxHeight'
@@ -106,6 +110,7 @@ const JsonSchemaViewerInner = ({
106110
const jsonSchemaTree = new JsonSchemaTree(schema, {
107111
mergeAllOf: true,
108112
refResolver: resolveRef,
113+
maxRefDepth,
109114
});
110115

111116
let nodeCount = 0;
@@ -134,7 +139,7 @@ const JsonSchemaViewerInner = ({
134139
jsonSchemaTreeRoot: jsonSchemaTree.root,
135140
nodeCount,
136141
};
137-
}, [schema, resolveRef, viewMode]);
142+
}, [schema, resolveRef, maxRefDepth, viewMode]);
138143

139144
React.useEffect(() => {
140145
onTreePopulated?.({

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,10 +2392,10 @@
23922392
json-schema-compare "^0.2.2"
23932393
lodash "^4.17.4"
23942394

2395-
"@stoplight/json-schema-tree@^2.2.5":
2396-
version "2.2.5"
2397-
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-tree/-/json-schema-tree-2.2.5.tgz#a3f78f3d475b74338f6d2da7ec6733a96cb9819f"
2398-
integrity sha512-H2d5EHbWJwbu4h7Eh3R4He4SGlfA5ScucpMqylVTgPwQImvikIyrI+v6oqzpl9fFZ6SkidfTcUs3z1+IKwxWdA==
2395+
"@stoplight/json-schema-tree@^2.3.0":
2396+
version "2.3.0"
2397+
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-tree/-/json-schema-tree-2.3.0.tgz#cdad7f7571700016d8e0e5bad59d287e9bb782d0"
2398+
integrity sha512-IH4SYuvV0C4maYQEPftduDBG1qVV4hy5ZXzS9rgq3V7zCT34I7xVwX9Vmpl0mOQTh2IZaTcyPWXkngt21ShJaQ==
23992399
dependencies:
24002400
"@stoplight/json" "^3.12.0"
24012401
"@stoplight/json-schema-merge-allof" "^0.7.8"

0 commit comments

Comments
 (0)