mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 20:47:45 +00:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user