diff --git a/index/rolodex.go b/index/rolodex.go index f377d63..f12db5a 100644 --- a/index/rolodex.go +++ b/index/rolodex.go @@ -215,7 +215,17 @@ func NewRolodex(indexConfig *SpecIndexConfig) *Rolodex { } func (r *Rolodex) GetIgnoredCircularReferences() []*CircularReferenceResult { - return r.ignoredCircularReferences + debounced := make(map[string]*CircularReferenceResult) + for _, c := range r.ignoredCircularReferences { + if _, ok := debounced[c.LoopPoint.FullDefinition]; !ok { + debounced[c.LoopPoint.FullDefinition] = c + } + } + var debouncedResults []*CircularReferenceResult + for _, v := range debounced { + debouncedResults = append(debouncedResults, v) + } + return debouncedResults } func (r *Rolodex) GetIndexingDuration() time.Duration { diff --git a/index/rolodex_remote_loader.go b/index/rolodex_remote_loader.go index 1744be9..abfb45b 100644 --- a/index/rolodex_remote_loader.go +++ b/index/rolodex_remote_loader.go @@ -198,7 +198,7 @@ func NewRemoteFSWithConfig(specIndexConfig *SpecIndexConfig) (*RemoteFS, error) } else { // default http client client := &http.Client{ - Timeout: time.Second * 60, + Timeout: time.Second * 120, } rfs.RemoteHandlerFunc = func(url string) (*http.Response, error) { return client.Get(url) diff --git a/index/rolodex_test.go b/index/rolodex_test.go index 116079c..ff81ec8 100644 --- a/index/rolodex_test.go +++ b/index/rolodex_test.go @@ -438,7 +438,7 @@ components: assert.Len(t, rolodex.GetCaughtErrors(), 0) // multiple loops across two files - assert.Len(t, rolodex.GetIgnoredCircularReferences(), 3) + assert.Len(t, rolodex.GetIgnoredCircularReferences(), 1) } func TestRolodex_IndexCircularLookup_PolyItemsHttpOnly(t *testing.T) { @@ -505,12 +505,18 @@ components: required: - muffins properties: + chuffins: + type: object + allOf: + - $ref: "https://kjahsdkjahdkjashdas.com/third.yaml" + buffins: + type: object + allOf: + - $ref: "https://kjahsdkjahdkjashdas.com/second.yaml#/" muffins: type: object anyOf: - $ref: "https://kjahsdkjahdkjashdas.com/second.yaml#/components/schemas/CircleTest" - - $ref: "https://kjahsdkjahdkjashdas.com/second.yaml#/" - - $ref: "https://kjahsdkjahdkjashdas.com/third.yaml" ` var rootNode yaml.Node @@ -536,7 +542,7 @@ components: assert.Len(t, rolodex.GetCaughtErrors(), 0) // should only be a single loop. - assert.Len(t, rolodex.GetIgnoredCircularReferences(), 3) + assert.Len(t, rolodex.GetIgnoredCircularReferences(), 1) assert.Equal(t, rolodex.GetRootIndex().GetResolver().GetIndexesVisited(), 6) } diff --git a/index/spec_index_test.go b/index/spec_index_test.go index 5205d38..b04cd02 100644 --- a/index/spec_index_test.go +++ b/index/spec_index_test.go @@ -4,6 +4,7 @@ package index import ( + "bytes" "fmt" "github.com/pb33f/libopenapi/utils" "log" @@ -121,8 +122,9 @@ func TestSpecIndex_DigitalOcean(t *testing.T) { // create a handler that uses an env variable to capture any GITHUB_TOKEN in the OS ENV // and inject it into the request header, so this does not fail when running lots of local tests. if os.Getenv("GITHUB_TOKEN") != "" { + fmt.Println("GITHUB_TOKEN found, setting remote handler func") client := &http.Client{ - Timeout: time.Second * 60, + Timeout: time.Second * 120, } remoteFS.SetRemoteHandlerFunc(func(url string) (*http.Response, error) { request, _ := http.NewRequest(http.MethodGet, url, nil) @@ -233,7 +235,9 @@ func TestSpecIndex_DigitalOcean_LookupsNotAllowed(t *testing.T) { cf := &SpecIndexConfig{} cf.AvoidBuildIndex = true cf.AvoidCircularReferenceCheck = true - cf.Logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ + var op []byte + buf := bytes.NewBuffer(op) + cf.Logger = slog.New(slog.NewJSONHandler(buf, &slog.HandlerOptions{ Level: slog.LevelError, })) @@ -282,7 +286,9 @@ func TestSpecIndex_BaseURLError(t *testing.T) { cf.AvoidBuildIndex = true cf.AllowRemoteLookup = true cf.AvoidCircularReferenceCheck = true - cf.Logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ + var op []byte + buf := bytes.NewBuffer(op) + cf.Logger = slog.New(slog.NewJSONHandler(buf, &slog.HandlerOptions{ Level: slog.LevelError, }))