From e786402861b62d820f7777afc32974b8550b0e59 Mon Sep 17 00:00:00 2001 From: Amit Reinich Date: Thu, 11 Jan 2024 11:32:09 +0200 Subject: [PATCH] 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. --- what-changed/model/comparison_functions.go | 4 +++- what-changed/model/schema_test.go | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/what-changed/model/comparison_functions.go b/what-changed/model/comparison_functions.go index caf47ce0..cde10b9b 100644 --- a/what-changed/model/comparison_functions.go +++ b/what-changed/model/comparison_functions.go @@ -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(©) + return fmt.Sprint(copy) } return fmt.Sprint(v) diff --git a/what-changed/model/schema_test.go b/what-changed/model/schema_test.go index dfcd80ed..4c81de6c 100644 --- a/what-changed/model/schema_test.go +++ b/what-changed/model/schema_test.go @@ -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: