mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
Added a nill check to lookup.
was causing vacuum to crash during testing.
This commit is contained in:
@@ -336,7 +336,7 @@ func FindKeyNodeFull(key string, nodes []*yaml.Node) (keyNode *yaml.Node, labelN
|
||||
}
|
||||
}
|
||||
|
||||
if key == v.Content[x].Value {
|
||||
if len(v.Content) > 0 && key == v.Content[x].Value {
|
||||
if IsNodeMap(v) {
|
||||
if x+1 == len(v.Content) {
|
||||
return v, v.Content[x], NodeAlias(v.Content[x])
|
||||
|
||||
@@ -1002,6 +1002,47 @@ func TestDetermineJSONWhitespaceLength_None(t *testing.T) {
|
||||
assert.Equal(t, 0, DetermineWhitespaceLength(string(someBytes)))
|
||||
}
|
||||
|
||||
func TestFindFirstKeyNode_MergeTest(t *testing.T) {
|
||||
yml := []byte(`openapi: 3.0.3
|
||||
|
||||
x-a: &anchor
|
||||
important-field: true
|
||||
|
||||
x-b:
|
||||
<<: *anchor
|
||||
`)
|
||||
|
||||
var rootNode yaml.Node
|
||||
_ = yaml.Unmarshal(yml, &rootNode)
|
||||
|
||||
k, v := FindFirstKeyNode("important-field", rootNode.Content[0].Content[5].Content, 0)
|
||||
assert.NotNil(t, k)
|
||||
assert.NotNil(t, v)
|
||||
assert.Equal(t, "true", v.Value)
|
||||
|
||||
}
|
||||
|
||||
func TestFindKeyNodeFull_MergeTest(t *testing.T) {
|
||||
yml := []byte(`openapi: 3.0.3
|
||||
|
||||
x-a: &anchor
|
||||
important-field: true
|
||||
|
||||
x-b:
|
||||
<<: *anchor
|
||||
`)
|
||||
|
||||
var rootNode yaml.Node
|
||||
_ = yaml.Unmarshal(yml, &rootNode)
|
||||
|
||||
k, l, v := FindKeyNodeFull("servers", rootNode.Content[0].Content)
|
||||
assert.NotNil(t, k)
|
||||
assert.NotNil(t, v)
|
||||
assert.NotNil(t, l)
|
||||
assert.Equal(t, "true", v.Value)
|
||||
|
||||
}
|
||||
|
||||
func TestFindFirstKeyNode_DoubleMerge(t *testing.T) {
|
||||
yml := []byte(`openapi: 3.0.3
|
||||
|
||||
|
||||
Reference in New Issue
Block a user