This commit is contained in:
Tristan Cartledge
2023-12-06 14:54:55 +00:00
parent 367b64d6db
commit 53f342ba63
3 changed files with 11 additions and 7 deletions

View File

@@ -6,8 +6,6 @@ package index
import (
"strings"
"sync"
"gopkg.in/yaml.v3"
)
func isHttpMethod(val string) bool {
@@ -30,8 +28,7 @@ func isHttpMethod(val string) bool {
return false
}
func boostrapIndexCollections(rootNode *yaml.Node, index *SpecIndex) {
index.root = rootNode
func boostrapIndexCollections(index *SpecIndex) {
index.allRefs = make(map[string]*Reference)
index.allMappedRefs = make(map[string]*Reference)
index.refsByLine = make(map[string]map[int]bool)

View File

@@ -31,7 +31,7 @@ import (
// how the index is set up.
func NewSpecIndexWithConfig(rootNode *yaml.Node, config *SpecIndexConfig) *SpecIndex {
index := new(SpecIndex)
boostrapIndexCollections(rootNode, index)
boostrapIndexCollections(index)
index.config = config
index.rolodex = config.Rolodex
index.uri = config.uri
@@ -46,6 +46,8 @@ func NewSpecIndexWithConfig(rootNode *yaml.Node, config *SpecIndexConfig) *SpecI
Level: slog.LevelError,
}))
}
index.root = rootNode
return createNewIndex(rootNode, index, config.AvoidBuildIndex)
}
@@ -58,7 +60,8 @@ func NewSpecIndexWithConfig(rootNode *yaml.Node, config *SpecIndexConfig) *SpecI
func NewSpecIndex(rootNode *yaml.Node) *SpecIndex {
index := new(SpecIndex)
index.config = CreateOpenAPIIndexConfig()
boostrapIndexCollections(rootNode, index)
index.root = rootNode
boostrapIndexCollections(index)
return createNewIndex(rootNode, index, false)
}
@@ -717,7 +720,7 @@ func (index *SpecIndex) GetRawReferenceCount() int {
// GetComponentSchemaCount will return the number of schemas located in the 'components' or 'definitions' node.
func (index *SpecIndex) GetComponentSchemaCount() int {
if index.root == nil {
if index.root == nil || len(index.root.Content) == 0 {
return -1
}

View File

@@ -533,6 +533,10 @@ func GenerateCleanSpecConfigBaseURL(baseURL *url.URL, dir string, includeFile bo
}
func syncMapToMap[K comparable, V any](sm *sync.Map) map[K]V {
if sm == nil {
return nil
}
m := make(map[K]V)
sm.Range(func(key, value interface{}) bool {