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>
This commit is contained in:
Dave Shanley
2023-05-16 16:12:32 -04:00
parent 08c9ca8c26
commit f629c0ff58
13 changed files with 1383 additions and 1268 deletions

View File

@@ -32,6 +32,8 @@ func NewSpecIndexWithConfig(rootNode *yaml.Node, config *SpecIndexConfig) *SpecI
}
config.remoteLock = &sync.Mutex{}
index.config = config
index.parentIndex = config.ParentIndex
index.uri = config.uri
if rootNode == nil || len(rootNode.Content) <= 0 {
return index
}
@@ -47,7 +49,7 @@ func NewSpecIndexWithConfig(rootNode *yaml.Node, config *SpecIndexConfig) *SpecI
// defaults to allowing remote references and file references. This is a potential security risk and should be controlled by
// providing a SpecIndexConfig that explicitly sets the AllowRemoteLookup and AllowFileLookup to true.
// This function also does not support specifications with relative references that may not exist locally.
// - https://github.com/pb33f/libopenapi/issues/73
// - https://github.com/pb33f/libopenapi/issues/73
func NewSpecIndex(rootNode *yaml.Node) *SpecIndex {
index := new(SpecIndex)
index.config = CreateOpenAPIIndexConfig()