bashing through usecases and updating tests as we go.

so many things that can go wrong. have to catch them all.

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2023-10-19 15:18:33 -04:00
parent 054103b733
commit b295e8fd5c
11 changed files with 404 additions and 181 deletions

View File

@@ -62,7 +62,16 @@ func (index *SpecIndex) FindComponent(componentId string, parent *yaml.Node) *Re
}
} else {
if !strings.Contains(componentId, "#") {
return index.lookupRolodex(uri)
// does it contain a file extension?
fileExt := filepath.Ext(componentId)
if fileExt != "" {
return index.lookupRolodex(uri)
}
// root search
return index.FindComponentInRoot(componentId)
}
return index.FindComponentInRoot(fmt.Sprintf("#/%s", uri[0]))
}
@@ -368,6 +377,7 @@ func (index *SpecIndex) lookupRolodex(uri []string) *Reference {
if index.specAbsolutePath != "" {
if index.config.BaseURL != nil {
// consider the file remote.
//if strings.Contains(file, "../../") {
// extract the base path from the specAbsolutePath for this index.
@@ -384,8 +394,11 @@ func (index *SpecIndex) lookupRolodex(uri []string) *Reference {
//absoluteFileLocation = loc
} else {
panic("nooooooo")
absoluteFileLocation, _ = filepath.Abs(filepath.Join(index.config.BaseURL.Path, file))
// consider the file local
dir := filepath.Dir(index.config.SpecAbsolutePath)
absoluteFileLocation, _ = filepath.Abs(filepath.Join(dir, file))
}
} else {
absoluteFileLocation = file