From 440ff3853f6fa9975eb6b386cf602aec1597b604 Mon Sep 17 00:00:00 2001 From: Calvin Lobo Date: Mon, 19 Aug 2024 11:46:00 -0400 Subject: [PATCH] Added GetAllReferences() and GetAllMappedReferences() methods to Rolodex --- functions/openapi/unused_component.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/functions/openapi/unused_component.go b/functions/openapi/unused_component.go index c8dab9b9..f816ed01 100644 --- a/functions/openapi/unused_component.go +++ b/functions/openapi/unused_component.go @@ -10,7 +10,6 @@ import ( "github.com/pb33f/libopenapi/index" "github.com/pb33f/libopenapi/utils" "gopkg.in/yaml.v3" - "maps" "strings" ) @@ -40,11 +39,7 @@ func (uc UnusedComponent) RunRule(nodes []*yaml.Node, context model.RuleFunction var results []model.RuleFunctionResult // extract all references, and every single component, recursively - allRefs := context.Document.GetRolodex().GetRootIndex().GetAllReferences() - for _, idx := range context.Document.GetRolodex().GetIndexes() { - refs := idx.GetAllReferences() - maps.Copy(allRefs, refs) - } + allRefs := context.Document.GetRolodex().GetAllReferences() schemas := context.Index.GetAllComponentSchemas() responses := context.Index.GetAllResponses() parameters := context.Index.GetAllParameters() @@ -54,12 +49,7 @@ func (uc UnusedComponent) RunRule(nodes []*yaml.Node, context model.RuleFunction securitySchemes := context.Index.GetAllSecuritySchemes() links := context.Index.GetAllLinks() callbacks := context.Index.GetAllCallbacks() - - mappedRefs := context.Document.GetRolodex().GetRootIndex().GetMappedReferences() - for _, idx := range context.Document.GetRolodex().GetIndexes() { - refs := idx.GetMappedReferences() - maps.Copy(mappedRefs, refs) - } + mappedRefs := context.Document.GetRolodex().GetAllMappedReferences() // extract securityRequirements from swagger. These are not mapped as they are not $refs // so, we need to map them as if they were.