mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 12:37:48 +00:00
More coverage tuning and cleaning
Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -401,8 +401,6 @@ func ExtractArray[T Buildable[N], N any](ctx context.Context, label string, root
|
|||||||
if !utils.IsNodeArray(vn) {
|
if !utils.IsNodeArray(vn) {
|
||||||
return []ValueReference[T]{}, nil, nil,
|
return []ValueReference[T]{}, nil, nil,
|
||||||
fmt.Errorf("array build failed, input is not an array, line %d, column %d", vn.Line, vn.Column)
|
fmt.Errorf("array build failed, input is not an array, line %d, column %d", vn.Line, vn.Column)
|
||||||
} else {
|
|
||||||
vn = fvn
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2033,6 +2033,52 @@ func TestLocateRefEnd_Loop(t *testing.T) {
|
|||||||
rolo.AddLocalFS(cf.BasePath, localFs)
|
rolo.AddLocalFS(cf.BasePath, localFs)
|
||||||
rolo.SetRootNode(&bsn)
|
rolo.SetRootNode(&bsn)
|
||||||
rolo.IndexTheRolodex()
|
rolo.IndexTheRolodex()
|
||||||
|
|
||||||
|
idx := rolo.GetRootIndex()
|
||||||
|
loop := yaml.Node{
|
||||||
|
Kind: yaml.MappingNode,
|
||||||
|
Content: []*yaml.Node{
|
||||||
|
{
|
||||||
|
Kind: yaml.ScalarNode,
|
||||||
|
Value: "$ref",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: yaml.ScalarNode,
|
||||||
|
Value: "third.yaml#/properties/property/properties/statistics",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
wd, _ := os.Getwd()
|
||||||
|
cp, _ := filepath.Abs(filepath.Join(wd, "../../test_specs/first.yaml"))
|
||||||
|
ctx := context.WithValue(context.Background(), index.CurrentPathKey, cp)
|
||||||
|
n, i, e, c := LocateRefEnd(ctx, &loop, idx, 0)
|
||||||
|
assert.NotNil(t, n)
|
||||||
|
assert.NotNil(t, i)
|
||||||
|
assert.Nil(t, e)
|
||||||
|
assert.NotNil(t, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocateRefEnd_Loop_WithResolve(t *testing.T) {
|
||||||
|
|
||||||
|
yml, _ := os.ReadFile("../../test_specs/first.yaml")
|
||||||
|
var bsn yaml.Node
|
||||||
|
_ = yaml.Unmarshal(yml, &bsn)
|
||||||
|
|
||||||
|
cf := index.CreateOpenAPIIndexConfig()
|
||||||
|
cf.BasePath = "../../test_specs"
|
||||||
|
|
||||||
|
localFSConfig := &index.LocalFSConfig{
|
||||||
|
BaseDirectory: cf.BasePath,
|
||||||
|
FileFilters: []string{"first.yaml", "second.yaml", "third.yaml", "fourth.yaml"},
|
||||||
|
DirFS: os.DirFS(cf.BasePath),
|
||||||
|
}
|
||||||
|
localFs, _ := index.NewLocalFSWithConfig(localFSConfig)
|
||||||
|
rolo := index.NewRolodex(cf)
|
||||||
|
rolo.AddLocalFS(cf.BasePath, localFs)
|
||||||
|
rolo.SetRootNode(&bsn)
|
||||||
|
rolo.IndexTheRolodex()
|
||||||
|
rolo.Resolve()
|
||||||
idx := rolo.GetRootIndex()
|
idx := rolo.GetRootIndex()
|
||||||
loop := yaml.Node{
|
loop := yaml.Node{
|
||||||
Kind: yaml.MappingNode,
|
Kind: yaml.MappingNode,
|
||||||
@@ -2102,3 +2148,24 @@ func TestLocateRefEnd_Empty(t *testing.T) {
|
|||||||
assert.Equal(t, "reference at line 0, column 0 is empty, it cannot be resolved", e.Error())
|
assert.Equal(t, "reference at line 0, column 0 is empty, it cannot be resolved", e.Error())
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestArray_NotRefNotArray(t *testing.T) {
|
||||||
|
|
||||||
|
yml := ``
|
||||||
|
var idxNode yaml.Node
|
||||||
|
mErr := yaml.Unmarshal([]byte(yml), &idxNode)
|
||||||
|
assert.NoError(t, mErr)
|
||||||
|
idx := index.NewSpecIndexWithConfig(&idxNode, index.CreateClosedAPIIndexConfig())
|
||||||
|
|
||||||
|
yml = `limes:
|
||||||
|
not: array`
|
||||||
|
|
||||||
|
var cNode yaml.Node
|
||||||
|
e := yaml.Unmarshal([]byte(yml), &cNode)
|
||||||
|
assert.NoError(t, e)
|
||||||
|
things, _, _, err := ExtractArray[*test_noGood](context.Background(), "limes", cNode.Content[0], idx)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, err.Error(), "array build failed, input is not an array, line 2, column 3")
|
||||||
|
assert.Len(t, things, 0)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -221,7 +221,8 @@ func TestPaths_Build_BadParams(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_ = n.Build(context.Background(), nil, idxNode.Content[0], idx)
|
_ = n.Build(context.Background(), nil, idxNode.Content[0], idx)
|
||||||
assert.Contains(t, buf.String(), "array build failed, input is not an array, line 3, column 5'")
|
er := buf.String()
|
||||||
|
assert.Contains(t, er, "array build failed, input is not an array, line 3, column 5'")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ additionalProperties: false
|
|||||||
maxProperties: 1
|
maxProperties: 1
|
||||||
|
|
||||||
properties:
|
properties:
|
||||||
|
pencils:
|
||||||
|
$ref: '#/properties/property/properties/statistics'
|
||||||
property:
|
property:
|
||||||
title: title of third prop in third doc
|
title: title of third prop in third doc
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
Reference in New Issue
Block a user