diff --git a/datamodel/low/extraction_functions.go b/datamodel/low/extraction_functions.go index 6cc1e20..d0037b2 100644 --- a/datamodel/low/extraction_functions.go +++ b/datamodel/low/extraction_functions.go @@ -401,8 +401,6 @@ func ExtractArray[T Buildable[N], N any](ctx context.Context, label string, root if !utils.IsNodeArray(vn) { return []ValueReference[T]{}, nil, nil, fmt.Errorf("array build failed, input is not an array, line %d, column %d", vn.Line, vn.Column) - } else { - vn = fvn } } } diff --git a/datamodel/low/extraction_functions_test.go b/datamodel/low/extraction_functions_test.go index 88254f4..4bb0eb3 100644 --- a/datamodel/low/extraction_functions_test.go +++ b/datamodel/low/extraction_functions_test.go @@ -2033,6 +2033,52 @@ func TestLocateRefEnd_Loop(t *testing.T) { rolo.AddLocalFS(cf.BasePath, localFs) rolo.SetRootNode(&bsn) 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() loop := yaml.Node{ 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.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) + +} diff --git a/datamodel/low/v3/paths_test.go b/datamodel/low/v3/paths_test.go index 69fbf8f..a4d78eb 100644 --- a/datamodel/low/v3/paths_test.go +++ b/datamodel/low/v3/paths_test.go @@ -221,7 +221,8 @@ func TestPaths_Build_BadParams(t *testing.T) { assert.NoError(t, err) _ = 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'") } diff --git a/test_specs/third.yaml b/test_specs/third.yaml index ba14cc2..2eb586c 100644 --- a/test_specs/third.yaml +++ b/test_specs/third.yaml @@ -6,7 +6,8 @@ additionalProperties: false maxProperties: 1 properties: - + pencils: + $ref: '#/properties/property/properties/statistics' property: title: title of third prop in third doc type: object