mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
adding in path overlap feature
discovered glitch when reworking test for pipeline Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -230,9 +231,9 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
|
||||
|
||||
// if the index has a base path, use that to resolve the path
|
||||
if index.config.BasePath != "" && index.config.BaseURL == nil {
|
||||
abs, _ := filepath.Abs(filepath.Join(index.config.BasePath, uri[0]))
|
||||
abs, _ := filepath.Abs(utils.CheckPathOverlap(index.config.BasePath, uri[0], string(os.PathSeparator)))
|
||||
if abs != defRoot {
|
||||
abs, _ = filepath.Abs(filepath.Join(defRoot, uri[0]))
|
||||
abs, _ = filepath.Abs(utils.CheckPathOverlap(defRoot, uri[0], string(os.PathSeparator)))
|
||||
}
|
||||
fullDefinitionPath = fmt.Sprintf("%s#/%s", abs, uri[1])
|
||||
componentName = fmt.Sprintf("#/%s", uri[1])
|
||||
@@ -247,14 +248,15 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
|
||||
} else {
|
||||
u = *index.config.BaseURL
|
||||
}
|
||||
abs, _ := filepath.Abs(filepath.Join(u.Path, uri[0]))
|
||||
//abs, _ := filepath.Abs(filepath.Join(u.Path, uri[0]))
|
||||
abs, _ := filepath.Abs(utils.CheckPathOverlap(u.Path, uri[0], string(os.PathSeparator)))
|
||||
|
||||
u.Path = utils.ReplaceWindowsDriveWithLinuxPath(abs)
|
||||
fullDefinitionPath = fmt.Sprintf("%s#/%s", u.String(), uri[1])
|
||||
componentName = fmt.Sprintf("#/%s", uri[1])
|
||||
|
||||
} else {
|
||||
|
||||
abs, _ := filepath.Abs(filepath.Join(defRoot, uri[0]))
|
||||
abs, _ := filepath.Abs(utils.CheckPathOverlap(defRoot, uri[0], string(os.PathSeparator)))
|
||||
fullDefinitionPath = fmt.Sprintf("%s#/%s", abs, uri[1])
|
||||
componentName = fmt.Sprintf("#/%s", uri[1])
|
||||
}
|
||||
@@ -274,7 +276,8 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
|
||||
if !filepath.IsAbs(uri[0]) {
|
||||
u, _ := url.Parse(defRoot)
|
||||
pathDir := filepath.Dir(u.Path)
|
||||
pathAbs, _ := filepath.Abs(filepath.Join(pathDir, uri[0]))
|
||||
//pathAbs, _ := filepath.Abs(filepath.Join(pathDir, uri[0]))
|
||||
pathAbs, _ := filepath.Abs(utils.CheckPathOverlap(pathDir, uri[0], string(os.PathSeparator)))
|
||||
pathAbs = utils.ReplaceWindowsDriveWithLinuxPath(pathAbs)
|
||||
u.Path = pathAbs
|
||||
fullDefinitionPath = u.String()
|
||||
@@ -283,9 +286,9 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
|
||||
if !filepath.IsAbs(uri[0]) {
|
||||
// if the index has a base path, use that to resolve the path
|
||||
if index.config.BasePath != "" {
|
||||
abs, _ := filepath.Abs(filepath.Join(index.config.BasePath, uri[0]))
|
||||
abs, _ := filepath.Abs(utils.CheckPathOverlap(index.config.BasePath, uri[0], string(os.PathSeparator)))
|
||||
if abs != defRoot {
|
||||
abs, _ = filepath.Abs(filepath.Join(defRoot, uri[0]))
|
||||
abs, _ = filepath.Abs(utils.CheckPathOverlap(defRoot, uri[0], string(os.PathSeparator)))
|
||||
}
|
||||
fullDefinitionPath = abs
|
||||
componentName = uri[0]
|
||||
@@ -294,13 +297,13 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
|
||||
if index.config.BaseURL != nil {
|
||||
|
||||
u := *index.config.BaseURL
|
||||
abs := filepath.Join(u.Path, uri[0])
|
||||
abs := utils.CheckPathOverlap(u.Path, uri[0], string(os.PathSeparator))
|
||||
abs = utils.ReplaceWindowsDriveWithLinuxPath(abs)
|
||||
u.Path = abs
|
||||
fullDefinitionPath = u.String()
|
||||
componentName = uri[0]
|
||||
} else {
|
||||
abs, _ := filepath.Abs(filepath.Join(defRoot, uri[0]))
|
||||
abs, _ := filepath.Abs(utils.CheckPathOverlap(defRoot, uri[0], string(os.PathSeparator)))
|
||||
fullDefinitionPath = abs
|
||||
componentName = uri[0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user