mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
Merge branch 'main' into ordered-libopenapi
This commit is contained in:
@@ -310,7 +310,8 @@ func (resolver *Resolver) VisitReference(ref *Reference, seen map[string]bool, j
|
|||||||
}
|
}
|
||||||
|
|
||||||
journey = append(journey, ref)
|
journey = append(journey, ref)
|
||||||
relatives := resolver.extractRelatives(ref, ref.Node, nil, seen, journey, resolve)
|
seenRelatives := make(map[int]bool)
|
||||||
|
relatives := resolver.extractRelatives(ref, ref.Node, nil, seen, journey, seenRelatives, resolve, 0)
|
||||||
|
|
||||||
seen = make(map[string]bool)
|
seen = make(map[string]bool)
|
||||||
|
|
||||||
@@ -421,19 +422,50 @@ func (resolver *Resolver) isInfiniteCircularDependency(ref *Reference, visitedDe
|
|||||||
|
|
||||||
func (resolver *Resolver) extractRelatives(ref *Reference, node, parent *yaml.Node,
|
func (resolver *Resolver) extractRelatives(ref *Reference, node, parent *yaml.Node,
|
||||||
foundRelatives map[string]bool,
|
foundRelatives map[string]bool,
|
||||||
journey []*Reference, resolve bool) []*Reference {
|
journey []*Reference, seen map[int]bool, resolve bool, depth int) []*Reference {
|
||||||
|
|
||||||
if len(journey) > 100 {
|
if len(journey) > 100 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is a safety check to prevent a stack overflow.
|
||||||
|
if depth > 500 {
|
||||||
|
def := "unknown"
|
||||||
|
if ref != nil {
|
||||||
|
def = ref.FullDefinition
|
||||||
|
}
|
||||||
|
if resolver.specIndex != nil && resolver.specIndex.logger != nil {
|
||||||
|
resolver.specIndex.logger.Warn("libopenapi resolver: relative depth exceeded 500 levels, "+
|
||||||
|
"check for circular references - resolving may be incomplete",
|
||||||
|
"reference", def)
|
||||||
|
}
|
||||||
|
|
||||||
|
loop := append(journey, ref)
|
||||||
|
circRef := &CircularReferenceResult{
|
||||||
|
Journey: loop,
|
||||||
|
Start: ref,
|
||||||
|
LoopIndex: depth,
|
||||||
|
LoopPoint: ref,
|
||||||
|
}
|
||||||
|
resolver.circularReferences = append(resolver.circularReferences, circRef)
|
||||||
|
resolver.resolvingErrors = append(resolver.resolvingErrors, &ResolvingError{
|
||||||
|
ErrorRef: fmt.Errorf("circular reference detected: %s", circRef.GenerateJourneyPath()),
|
||||||
|
Node: node,
|
||||||
|
Path: circRef.GenerateJourneyPath(),
|
||||||
|
})
|
||||||
|
ref.Circular = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var found []*Reference
|
var found []*Reference
|
||||||
|
|
||||||
if len(node.Content) > 0 {
|
if len(node.Content) > 0 {
|
||||||
for i, n := range node.Content {
|
for i, n := range node.Content {
|
||||||
if utils.IsNodeMap(n) || utils.IsNodeArray(n) {
|
if utils.IsNodeMap(n) || utils.IsNodeArray(n) {
|
||||||
|
depth++
|
||||||
|
|
||||||
|
found = append(found, resolver.extractRelatives(ref, n, node, foundRelatives, journey, seen, resolve, depth)...)
|
||||||
|
|
||||||
found = append(found, resolver.extractRelatives(ref, n, node, foundRelatives, journey, resolve)...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i%2 == 0 && n.Value == "$ref" {
|
if i%2 == 0 && n.Value == "$ref" {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user