in packages/rulesets/src/native/utilities/ref-helper.ts [12:40]
export function crawlReference(doc: any, schema: any, inventory?: ISwaggerInventory): any {
const getRefModel = (docToSearch: any, refValue: string, visited: string[]) => {
if (visited.includes(refValue)) {
throw new Error("Found circle reference: " + visited.join("->"))
}
visited.push(refValue)
const refSlices = parseJsonRef(refValue)
const pathExpression = refSlices[1].split("/").slice(1)
try {
const result = nodes(docToSearch, stringify(pathExpression))
return result.length !== 0 ? result[0].value : undefined
} catch (err) {
return undefined
}
}
if (schema && doc) {
if (schema.$ref) {
const refSlices = parseJsonRef(schema.$ref)
if (inventory && refSlices[0]) {
doc = inventory.getDocuments(refSlices[0])
}
schema = getRefModel(doc, `#${refSlices[1]}`, [])
return crawlReference(doc, schema, inventory)
}
return schema
}
return undefined
}