Skip to content

Commit ff2db82

Browse files
committed
fix: safer property access
1 parent a2e6363 commit ff2db82

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/tree/populateTree.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isLocalRef } from '@stoplight/json';
22
import { TreeListNode, TreeListParentNode } from '@stoplight/tree-list';
33
import { JsonPath } from '@stoplight/types';
44
import { JSONSchema4 } from 'json-schema';
5+
import { isObject as _isObject } from 'lodash-es';
56
import { IArrayNode, IObjectNode, SchemaKind, SchemaNode, SchemaTreeListNode } from '../types';
67
import { mergeAllOf } from '../utils';
78
import { getPrimaryType } from '../utils/getPrimaryType';
@@ -56,7 +57,7 @@ export const populateTree: Walker = (schema, parent, level, path, options): unde
5657
} else if (node.combiner === 'allOf' && options?.mergeAllOf) {
5758
parent.children.pop();
5859
populateTree(mergeAllOf(schema), parent, level, path, options);
59-
} else if (node.properties !== void 0) {
60+
} else if (_isObject(node.properties)) {
6061
(treeNode as TreeListParentNode).children = [];
6162

6263
for (const [i, property] of node.properties.entries()) {
@@ -97,7 +98,7 @@ function processArray(
9798
children.push(child);
9899
}
99100
}
100-
} else if (schema.items !== void 0) {
101+
} else if (_isObject(schema.items)) {
101102
const subtype = getPrimaryType(schema.items);
102103
switch (subtype) {
103104
case SchemaKind.Object:
@@ -123,7 +124,7 @@ function processObject(
123124
): TreeListNode {
124125
const children: TreeListNode[] = [];
125126

126-
if (schema.properties !== void 0) {
127+
if (_isObject(schema.properties)) {
127128
(node as TreeListParentNode).children = children;
128129

129130
for (const [prop, property] of Object.entries(schema.properties)) {
@@ -140,7 +141,7 @@ function processObject(
140141
}
141142
}
142143

143-
if (schema.patternProperties !== void 0) {
144+
if (_isObject(schema.patternProperties)) {
144145
(node as TreeListParentNode).children = children;
145146

146147
for (const [prop, property] of Object.entries(schema.patternProperties)) {

0 commit comments

Comments
 (0)