All spec_index tests pass

It’s so, so much faster than before, intelligent and ready for scale. I’m excited!

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2023-10-20 11:38:29 -04:00
parent b295e8fd5c
commit 1bf772ab69
4 changed files with 280 additions and 240 deletions

View File

@@ -6,6 +6,7 @@ package index
import (
"errors"
"fmt"
"net/url"
"path/filepath"
"strings"
@@ -207,8 +208,13 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
// determine absolute path to this definition
// TODO: come and clean this mess up.
var iroot string
if strings.HasPrefix(index.specAbsolutePath, "http") {
iroot = index.specAbsolutePath
} else {
iroot = filepath.Dir(index.specAbsolutePath)
}
iroot := filepath.Dir(index.specAbsolutePath)
var componentName string
var fullDefinitionPath string
if len(uri) == 2 {
@@ -239,6 +245,15 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
} else {
fullDefinitionPath = uri[0]
componentName = uri[0]
if strings.HasPrefix(iroot, "http") {
if !filepath.IsAbs(uri[0]) {
u, _ := url.Parse(iroot)
pathDir := filepath.Dir(u.Path)
pathAbs, _ := filepath.Abs(filepath.Join(pathDir, uri[0]))
u.Path = pathAbs
fullDefinitionPath = u.String()
}
}
}
}
}