mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 04:20:11 +00:00
build working on windows again
ping pong.
This commit is contained in:
@@ -249,8 +249,8 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
|
||||
u = *index.config.BaseURL
|
||||
}
|
||||
//abs, _ := filepath.Abs(filepath.Join(u.Path, uri[0]))
|
||||
abs, _ := filepath.Abs(utils.CheckPathOverlap(u.Path, uri[0], string(os.PathSeparator)))
|
||||
|
||||
//abs, _ := filepath.Abs(utils.CheckPathOverlap(u.Path, uri[0], string(os.PathSeparator)))
|
||||
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])
|
||||
@@ -611,7 +611,7 @@ func (index *SpecIndex) ExtractComponentsFromRefs(refs []*Reference) []*Referenc
|
||||
for _, ref := range refs {
|
||||
|
||||
// check reference for backslashes (hah yeah seen this too!)
|
||||
if strings.Contains(ref.Definition, "\\") { // this was from blazemeter.com haha!
|
||||
if strings.Contains(ref.Definition, "\\\\") {
|
||||
_, path := utils.ConvertComponentIdIntoFriendlyPathSearch(ref.Definition)
|
||||
indexError := &IndexingError{
|
||||
Err: fmt.Errorf("component '%s' contains a backslash '\\'. It's not valid", ref.Definition),
|
||||
|
||||
@@ -478,6 +478,8 @@ components:
|
||||
fourthFile.WriteString(fourth)
|
||||
fifthFile.WriteString(fifth)
|
||||
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
baseDir := "tmp-a"
|
||||
|
||||
fsCfg := &LocalFSConfig{
|
||||
|
||||
@@ -913,7 +913,7 @@ func TestSpecIndex_ExtractComponentsFromRefs(t *testing.T) {
|
||||
_ = yaml.Unmarshal([]byte(yml), &rootNode)
|
||||
|
||||
index := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig())
|
||||
assert.Len(t, index.GetReferenceIndexErrors(), 1)
|
||||
assert.Len(t, index.GetReferenceIndexErrors(), 0)
|
||||
}
|
||||
|
||||
func TestSpecIndex_FindComponent_WithACrazyAssPath(t *testing.T) {
|
||||
|
||||
@@ -6,6 +6,7 @@ package index
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -131,14 +132,16 @@ func extractRequiredReferenceProperties(fulldef string, idx *SpecIndex, required
|
||||
if r[0] == "" {
|
||||
abs = u.Path
|
||||
} else {
|
||||
abs, _ = filepath.Abs(filepath.Join(filepath.Dir(u.Path), r[0]))
|
||||
abs, _ = filepath.Abs(utils.CheckPathOverlap(filepath.Dir(u.Path), r[0],
|
||||
string(os.PathSeparator)))
|
||||
}
|
||||
|
||||
u.Path = utils.ReplaceWindowsDriveWithLinuxPath(abs)
|
||||
u.Fragment = ""
|
||||
defPath = fmt.Sprintf("%s#/%s", u.String(), r[1])
|
||||
} else {
|
||||
u.Path = utils.ReplaceWindowsDriveWithLinuxPath(filepath.Join(filepath.Dir(u.Path), r[0]))
|
||||
u.Path = utils.ReplaceWindowsDriveWithLinuxPath(utils.CheckPathOverlap(filepath.Dir(u.Path),
|
||||
r[0], string(os.PathSeparator)))
|
||||
u.Fragment = ""
|
||||
defPath = u.String()
|
||||
}
|
||||
@@ -149,12 +152,17 @@ func extractRequiredReferenceProperties(fulldef string, idx *SpecIndex, required
|
||||
if r[0] == "" {
|
||||
abs, _ = filepath.Abs(exp[0])
|
||||
} else {
|
||||
abs, _ = filepath.Abs(filepath.Join(filepath.Dir(exp[0]), r[0]))
|
||||
abs, _ = filepath.Abs(utils.CheckPathOverlap(filepath.Dir(exp[0]), r[0],
|
||||
string(os.PathSeparator)))
|
||||
|
||||
//abs, _ = filepath.Abs(filepath.Join(filepath.Dir(exp[0]), r[0],
|
||||
// string('J')))
|
||||
}
|
||||
|
||||
defPath = fmt.Sprintf("%s#/%s", abs, r[1])
|
||||
} else {
|
||||
defPath, _ = filepath.Abs(filepath.Join(filepath.Dir(exp[0]), r[0]))
|
||||
defPath, _ = filepath.Abs(utils.CheckPathOverlap(filepath.Dir(exp[0]),
|
||||
r[0], string(os.PathSeparator)))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -165,17 +173,18 @@ func extractRequiredReferenceProperties(fulldef string, idx *SpecIndex, required
|
||||
u, _ := url.Parse(exp[0])
|
||||
r := strings.Split(refName, "#/")
|
||||
if len(r) == 2 {
|
||||
abs, _ := filepath.Abs(filepath.Join(filepath.Dir(u.Path), r[0]))
|
||||
abs, _ := filepath.Abs(utils.CheckPathOverlap(filepath.Dir(u.Path), r[0], string(os.PathSeparator)))
|
||||
u.Path = utils.ReplaceWindowsDriveWithLinuxPath(abs)
|
||||
u.Fragment = ""
|
||||
defPath = fmt.Sprintf("%s#/%s", u.String(), r[1])
|
||||
} else {
|
||||
u.Path = utils.ReplaceWindowsDriveWithLinuxPath(filepath.Join(filepath.Dir(u.Path), r[0]))
|
||||
u.Path = utils.ReplaceWindowsDriveWithLinuxPath(utils.CheckPathOverlap(filepath.Dir(u.Path),
|
||||
r[0], string(os.PathSeparator)))
|
||||
u.Fragment = ""
|
||||
defPath = u.String()
|
||||
}
|
||||
} else {
|
||||
defPath, _ = filepath.Abs(filepath.Join(filepath.Dir(exp[0]), refName))
|
||||
defPath, _ = filepath.Abs(utils.CheckPathOverlap(filepath.Dir(exp[0]), refName, string(os.PathSeparator)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -15,9 +16,13 @@ func ReplaceWindowsDriveWithLinuxPath(path string) string {
|
||||
func CheckPathOverlap(pathA, pathB, sep string) string {
|
||||
a := strings.Split(pathA, sep)
|
||||
b := strings.Split(pathB, sep)
|
||||
|
||||
if strings.HasPrefix(a[len(a)-1], "/") && a[len(a)-1][1:] == b[0] {
|
||||
b = b[1:]
|
||||
}
|
||||
if a[len(a)-1] == b[0] {
|
||||
b = b[1:]
|
||||
}
|
||||
return strings.Join(append(a, b...), sep)
|
||||
f := filepath.Join(pathA, strings.Join(b, sep))
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReplaceWindowsDriveWithLinuxPath(t *testing.T) {
|
||||
path := `C:\Users\pb33f\go\src\github.com\pb33f\libopenapi\utils\windows_drive_test.go`
|
||||
@@ -22,6 +25,9 @@ func TestCheckPathOverlap(t *testing.T) {
|
||||
pathA := `C:\Users\pb33f`
|
||||
pathB := `pb33f\files\thing.yaml`
|
||||
expected := `C:\Users\pb33f\files\thing.yaml`
|
||||
if runtime.GOOS != "windows" {
|
||||
expected = `/Users/pb33f/files/thing.yaml`
|
||||
}
|
||||
result := CheckPathOverlap(pathA, pathB, `\`)
|
||||
if result != expected {
|
||||
t.Errorf("Expected %s, got %s", expected, result)
|
||||
@@ -32,6 +38,9 @@ func TestCheckPathOverlap_VariationA(t *testing.T) {
|
||||
pathA := `/Users/pb33f`
|
||||
pathB := `pb33f/files/thing.yaml`
|
||||
expected := `/Users/pb33f/files/thing.yaml`
|
||||
if runtime.GOOS == "windows" {
|
||||
expected = `\Users\pb33f\files\thing.yaml`
|
||||
}
|
||||
result := CheckPathOverlap(pathA, pathB, `/`)
|
||||
if result != expected {
|
||||
t.Errorf("Expected %s, got %s", expected, result)
|
||||
@@ -42,6 +51,9 @@ func TestCheckPathOverlap_VariationB(t *testing.T) {
|
||||
pathA := `somewhere/pb33f`
|
||||
pathB := `pb33f/files/thing.yaml`
|
||||
expected := `somewhere/pb33f/files/thing.yaml`
|
||||
if runtime.GOOS == "windows" {
|
||||
expected = `somewhere\pb33f\files\thing.yaml`
|
||||
}
|
||||
result := CheckPathOverlap(pathA, pathB, `/`)
|
||||
if result != expected {
|
||||
t.Errorf("Expected %s, got %s", expected, result)
|
||||
|
||||
Reference in New Issue
Block a user