(location)
| 975 | function detectRecursiveSchemas (context, location) { |
| 976 | const pathStack = new Set() |
| 977 | function traverse (location) { |
| 978 | const schema = location.schema |
| 979 | if (typeof schema !== 'object' || schema === null) return |
| 980 | |
| 981 | const schemaId = location.schemaId || '' |
| 982 | const jsonPointer = location.jsonPointer || '' |
| 983 | const fullPath = `${schemaId}#${jsonPointer}` |
| 984 | |
| 985 | if (pathStack.has(fullPath)) { |
| 986 | // Mark all nodes in the current path that are part of the cycle |
| 987 | let inCycle = false |
| 988 | for (const p of pathStack) { |
| 989 | if (p === fullPath) inCycle = true |
| 990 | if (inCycle) context.recursivePaths.add(p) |
| 991 | } |
| 992 | context.recursivePaths.add(fullPath) |
| 993 | return |
| 994 | } |
| 995 | pathStack.add(fullPath) |
| 996 | |
| 997 | if (schema.$ref) { |
| 998 | try { |
| 999 | const res = resolveRef(context, location) |
| 1000 | traverse(res) |
| 1001 | } catch (err) { |
| 1002 | // Validation will handle missing refs later |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | if (schema.properties) { |
| 1007 | const propertiesLocation = location.getPropertyLocation('properties') |
| 1008 | for (const key in schema.properties) { |
| 1009 | traverse(propertiesLocation.getPropertyLocation(key)) |
| 1010 | } |
| 1011 | } |
| 1012 | if (schema.additionalProperties && typeof schema.additionalProperties === 'object') { |
| 1013 | traverse(location.getPropertyLocation('additionalProperties')) |
| 1014 | } |
| 1015 | if (schema.patternProperties) { |
| 1016 | const patternPropertiesLocation = location.getPropertyLocation('patternProperties') |
| 1017 | for (const key in schema.patternProperties) { |
| 1018 | traverse(patternPropertiesLocation.getPropertyLocation(key)) |
| 1019 | } |
| 1020 | } |
| 1021 | if (schema.items) { |
| 1022 | const itemsLocation = location.getPropertyLocation('items') |
| 1023 | if (Array.isArray(schema.items)) { |
| 1024 | for (let i = 0; i < schema.items.length; i++) { |
| 1025 | traverse(itemsLocation.getPropertyLocation(i)) |
| 1026 | } |
| 1027 | } else { |
| 1028 | traverse(itemsLocation) |
| 1029 | } |
| 1030 | } |
| 1031 | if (schema.additionalItems && typeof schema.additionalItems === 'object') { |
| 1032 | traverse(location.getPropertyLocation('additionalItems')) |
| 1033 | } |
| 1034 |
no test coverage detected
searching dependent graphs…