Modified toString function to encode a copy instead of the real (re-used) object, added schema tests for model.ChangeContext line and column on enum changes.

This commit is contained in:
Amit Reinich
2024-01-11 11:32:09 +02:00
committed by quobix
parent d7c6474908
commit 2a1e4e5b91
2 changed files with 8 additions and 2 deletions

View File

@@ -405,7 +405,9 @@ func ExtractStringValueSliceChanges(lParam, rParam []low.ValueReference[string],
func toString(v any) string {
if y, ok := v.(*yaml.Node); ok {
_ = y.Encode(&v)
copy := *y
_ = copy.Encode(&copy)
return fmt.Sprint(copy)
}
return fmt.Sprint(v)

View File

@@ -460,6 +460,8 @@ components:
assert.Equal(t, PropertyAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "d", changes.Changes[0].New)
assert.Equal(t, v3.EnumLabel, changes.Changes[0].Property)
assert.Equal(t, 5, *changes.GetAllChanges()[0].Context.NewLine)
assert.Equal(t, 20, *changes.GetAllChanges()[0].Context.NewColumn)
}
func TestCompareSchemas_EnumRemoved(t *testing.T) {
@@ -488,6 +490,8 @@ components:
assert.Equal(t, PropertyRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "d", changes.Changes[0].Original)
assert.Equal(t, v3.EnumLabel, changes.Changes[0].Property)
assert.Equal(t, 5, *changes.GetAllChanges()[0].Context.OriginalLine)
assert.Equal(t, 20, *changes.GetAllChanges()[0].Context.OriginalColumn)
}
func TestCompareSchemas_PropertyAdded(t *testing.T) {
@@ -2711,7 +2715,7 @@ components:
- type: array
items:
type: string
example:
example:
oh: my`
right := `openapi: 3.0
components: