mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 12:37:48 +00:00
bumping coverage on utility methods in index.
Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -124,61 +124,23 @@ func extractRequiredReferenceProperties(fulldef string, requiredPropDefNode *yam
|
|||||||
if !strings.HasPrefix(exp[0], "http") {
|
if !strings.HasPrefix(exp[0], "http") {
|
||||||
|
|
||||||
if !filepath.IsAbs(exp[0]) {
|
if !filepath.IsAbs(exp[0]) {
|
||||||
|
abs, _ := filepath.Abs(filepath.Join(filepath.Dir(fulldef), exp[0]))
|
||||||
if strings.HasPrefix(fulldef, "http") {
|
defPath = fmt.Sprintf("%s#/%s", abs, exp[1])
|
||||||
|
|
||||||
u, _ := url.Parse(fulldef)
|
|
||||||
p := filepath.Dir(u.Path)
|
|
||||||
abs, _ := filepath.Abs(filepath.Join(p, exp[0]))
|
|
||||||
u.Path = abs
|
|
||||||
defPath = fmt.Sprintf("%s#/%s", u.String(), exp[1])
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
abs, _ := filepath.Abs(filepath.Join(filepath.Dir(fulldef), exp[0]))
|
|
||||||
defPath = fmt.Sprintf("%s#/%s", abs, exp[1])
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if strings.HasPrefix(exp[0], "http") {
|
if strings.HasPrefix(exp[0], "http") {
|
||||||
|
|
||||||
defPath = exp[0]
|
defPath = exp[0]
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// file shit again
|
|
||||||
|
|
||||||
if filepath.IsAbs(exp[0]) {
|
if filepath.IsAbs(exp[0]) {
|
||||||
|
|
||||||
defPath = exp[0]
|
defPath = exp[0]
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
defPath, _ = filepath.Abs(filepath.Join(filepath.Dir(fulldef), exp[0]))
|
||||||
// check full def and decide what to do next.
|
|
||||||
if strings.HasPrefix(fulldef, "http") {
|
|
||||||
|
|
||||||
u, _ := url.Parse(fulldef)
|
|
||||||
p := filepath.Dir(u.Path)
|
|
||||||
abs, _ := filepath.Abs(filepath.Join(p, exp[0]))
|
|
||||||
u.Path = abs
|
|
||||||
defPath = u.String()
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
defPath, _ = filepath.Abs(filepath.Join(filepath.Dir(fulldef), exp[0]))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := reqRefProps[defPath]; !ok {
|
if _, ok := reqRefProps[defPath]; !ok {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package index
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -48,6 +49,62 @@ func TestGenerateCleanSpecConfigBaseURL_HttpStrip(t *testing.T) {
|
|||||||
GenerateCleanSpecConfigBaseURL(u, "crap.yaml#thing", true))
|
GenerateCleanSpecConfigBaseURL(u, "crap.yaml#thing", true))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSpecIndex_extractDefinitionRequiredRefProperties(t *testing.T) {
|
func Test_extractRequiredReferenceProperties(t *testing.T) {
|
||||||
|
|
||||||
|
d := `$ref: http://internets/shoes`
|
||||||
|
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(d), &rootNode)
|
||||||
|
props := make(map[string][]string)
|
||||||
|
|
||||||
|
data := extractRequiredReferenceProperties("the-big.yaml#/cheese/thing",
|
||||||
|
rootNode.Content[0], "cakes", props)
|
||||||
|
assert.Len(t, props, 1)
|
||||||
|
assert.NotNil(t, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_extractRequiredReferenceProperties_singleFile(t *testing.T) {
|
||||||
|
|
||||||
|
d := `$ref: http://cake.yaml/camel.yaml`
|
||||||
|
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(d), &rootNode)
|
||||||
|
props := make(map[string][]string)
|
||||||
|
|
||||||
|
data := extractRequiredReferenceProperties("dingo-bingo-bango.yaml",
|
||||||
|
rootNode.Content[0], "cakes", props)
|
||||||
|
assert.Len(t, props, 1)
|
||||||
|
assert.NotNil(t, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_extractRequiredReferenceProperties_http(t *testing.T) {
|
||||||
|
|
||||||
|
d := `$ref: http://cake.yaml/camel.yaml`
|
||||||
|
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(d), &rootNode)
|
||||||
|
props := make(map[string][]string)
|
||||||
|
|
||||||
|
data := extractRequiredReferenceProperties("http://dingo-bingo-bango.yaml/camel.yaml",
|
||||||
|
rootNode.Content[0], "cakes", props)
|
||||||
|
assert.Len(t, props, 1)
|
||||||
|
assert.NotNil(t, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_extractRequiredReferenceProperties_abs(t *testing.T) {
|
||||||
|
|
||||||
|
d := `$ref: http://cake.yaml/camel.yaml`
|
||||||
|
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(d), &rootNode)
|
||||||
|
props := make(map[string][]string)
|
||||||
|
|
||||||
|
data := extractRequiredReferenceProperties("/camel.yaml",
|
||||||
|
rootNode.Content[0], "cakes", props)
|
||||||
|
assert.Len(t, props, 1)
|
||||||
|
assert.NotNil(t, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_extractDefinitionRequiredRefProperties_nil(t *testing.T) {
|
||||||
assert.Nil(t, extractDefinitionRequiredRefProperties(nil, nil, ""))
|
assert.Nil(t, extractDefinitionRequiredRefProperties(nil, nil, ""))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user