in src/services/jsonSchemaService.ts [540:591]
private traverseNodes(root: JSONSchema, handle: (node: JSONSchema) => void) {
if (!root || typeof root !== 'object') {
return Promise.resolve(null);
}
const seen = new Set<JSONSchema>();
const collectEntries = (...entries: (JSONSchemaRef | undefined)[]) => {
for (const entry of entries) {
if (typeof entry === 'object') {
toWalk.push(entry);
}
}
};
const collectMapEntries = (...maps: (JSONSchemaMap | undefined)[]) => {
for (const map of maps) {
if (typeof map === 'object') {
for (const k in map) {
const key = k as keyof JSONSchemaMap;
const entry = map[key];
if (typeof entry === 'object') {
toWalk.push(entry);
}
}
}
}
};
const collectArrayEntries = (...arrays: (JSONSchemaRef[] | undefined)[]) => {
for (const array of arrays) {
if (Array.isArray(array)) {
for (const entry of array) {
if (typeof entry === 'object') {
toWalk.push(entry);
}
}
}
}
};
const toWalk: JSONSchema[] = [root];
let next = toWalk.pop();
while (next) {
if (!seen.has(next)) {
seen.add(next);
handle(next);
collectEntries(<JSONSchema>next.items, next.additionalItems, <JSONSchema>next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
collectMapEntries(next.definitions, next.properties, next.patternProperties, <JSONSchemaMap>next.dependencies);
collectArrayEntries(next.anyOf, next.allOf, next.oneOf, <JSONSchema[]>next.items);
}
next = toWalk.pop();
}
};