Files
libopenapi/index/search_index.go
Dave Shanley f629c0ff58 fix for resolving looping relative references
In vacuum, a usecase was reported where an infinite loop occurred due to re-parsing the same reference over and over in a loop. It was re-creatable and it was because the loop happened before the index was ready.

This should be resolved now, at least for this use case. To be sure, I have included the specs as a new test.

https://github.com/daveshanley/vacuum/issues/268
Signed-off-by: Dave Shanley <dave@quobix.com>
2023-05-16 17:03:02 -04:00

35 lines
993 B
Go

// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package index
// SearchIndexForReference searches the index for a reference, first looking through the mapped references
// and then externalSpecIndex for a match. If no match is found, it will recursively search the child indexes
// extracted when parsing the OpenAPI Spec.
func (index *SpecIndex) SearchIndexForReference(ref string) []*Reference {
if r, ok := index.allMappedRefs[ref]; ok {
return []*Reference{r}
}
for c := range index.children {
found := goFindMeSomething(index.children[c], ref)
if found != nil {
return found
}
}
return nil
}
func (index *SpecIndex) SearchAncestryForSeenURI(uri string) *SpecIndex {
if index.parentIndex == nil {
return nil
}
if index.uri[0] != uri {
return index.parentIndex.SearchAncestryForSeenURI(uri)
}
return index
}
func goFindMeSomething(i *SpecIndex, ref string) []*Reference {
return i.SearchIndexForReference(ref)
}