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

@@ -6,6 +6,7 @@ package index
import (
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"os"
"testing"
)
@@ -26,6 +27,22 @@ func TestSpecIndex_performExternalLookup(t *testing.T) {
assert.Len(t, index.GetPathsNode().Content, 1)
}
func TestSpecIndex_CheckCircularIndex(t *testing.T) {
yml, _ := os.ReadFile("../test_specs/first.yaml")
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &rootNode)
c := CreateOpenAPIIndexConfig()
c.BasePath = "../test_specs"
index := NewSpecIndexWithConfig(&rootNode, c)
assert.Nil(t, index.uri)
assert.NotNil(t, index.children[0].uri)
assert.NotNil(t, index.children[0].children[0].uri)
assert.NotNil(t, index.SearchIndexForReference("second.yaml#/properties/property2"))
assert.NotNil(t, index.SearchIndexForReference("second.yaml"))
assert.Nil(t, index.SearchIndexForReference("fourth.yaml"))
}
func TestSpecIndex_performExternalLookup_invalidURL(t *testing.T) {
yml := `openapi: 3.1.0
components: