Skip to content

Commit 062469d

Browse files
authored
fix: address circular reference traversal slowdown (#20)
* fix: address circular reference traversal slowdown * chore: update comment
1 parent e096188 commit 062469d

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Available options:
6565
Don't include `writeOnly` object properties
6666
- **quiet** - `boolean`
6767
Don't log console warning messages
68+
- **maxSampleDepth** - `number`
69+
Max depth sampler should traverse
6870
- **doc** - the whole schema where the schema is taken from. Might be useful when the `schema` passed is only a portion of the whole schema and $refs aren't resected. **doc** must not contain any external references
6971

7072
## Example

Diff for: src/traverse.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ export function clearCache() {
1414
}
1515

1616
export function traverse(schema, options, doc, context) {
17-
// checking circular JS references by checking context
18-
// because context is passed only when traversing through nested objects happens
19-
if (context) {
20-
if (seenSchemasStack.includes(schema)) return getResultForCircular(inferType(schema));
21-
seenSchemasStack.push(schema);
22-
}
23-
17+
if (seenSchemasStack.includes(schema))
18+
return getResultForCircular(inferType(schema));
19+
seenSchemasStack.push(schema);
2420

21+
//context is passed only when traversing through nested objects happens
2522
if (context && context.depth > options.maxSampleDepth) {
2623
popSchemaStack(seenSchemasStack, context);
2724
return getResultForCircular(inferType(schema));

Diff for: src/types.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface Options {
55
readonly skipReadOnly?: boolean;
66
readonly skipWriteOnly?: boolean;
77
readonly quiet?: boolean;
8+
readonly maxSampleDepth?: number;
89
}
910

1011
export function sample(schema: JSONSchema7, options?: Options, document?: object): unknown;

0 commit comments

Comments
 (0)