Skip to content

Commit 58c609a

Browse files
califlowerdaveshanley
authored andcommitted
Fix swapped LeftNode and RightNode in exclusiveMaximum PropertyCheck
Fixes issue where LeftNode was assigned rnv and RightNode was assigned lnv, causing incorrect node references in change detection for exclusiveMaximum property comparisons. Addresses #451
1 parent 7c9a7f6 commit 58c609a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

what-changed/model/schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,8 @@ func checkSchemaPropertyChanges(
761761
}
762762
// ExclusiveMaximum
763763
props = append(props, &PropertyCheck{
764-
LeftNode: rnv,
765-
RightNode: lnv,
764+
LeftNode: lnv,
765+
RightNode: rnv,
766766
Label: v3.ExclusiveMaximumLabel,
767767
Changes: changes,
768768
Breaking: true,

what-changed/model/schema_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,6 +3591,45 @@ components:
35913591
changes.PropertiesOnly() // this does nothing in this lib.
35923592
}
35933593

3594+
func TestCompareSchemas_ExclusiveMaximumNodeSwap(t *testing.T) {
3595+
// Clear hash cache to ensure deterministic results in concurrent test environments
3596+
low.ClearHashCache()
3597+
left := `openapi: 3.1
3598+
components:
3599+
schemas:
3600+
TestSchema:
3601+
type: number
3602+
exclusiveMaximum: 100`
3603+
3604+
right := `openapi: 3.1
3605+
components:
3606+
schemas:
3607+
TestSchema:
3608+
type: number
3609+
exclusiveMaximum: 200`
3610+
3611+
leftDoc, rightDoc := test_BuildDoc(left, right)
3612+
3613+
// extract left reference schema and non reference schema.
3614+
lSchemaProxy := leftDoc.Components.Value.FindSchema("TestSchema").Value
3615+
rSchemaProxy := rightDoc.Components.Value.FindSchema("TestSchema").Value
3616+
3617+
changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
3618+
assert.NotNil(t, changes)
3619+
assert.Len(t, changes.GetAllChanges(), 1)
3620+
assert.Equal(t, changes.TotalChanges(), 1)
3621+
assert.Equal(t, changes.TotalBreakingChanges(), 1)
3622+
3623+
// Find the exclusiveMaximum change
3624+
exclusiveMaxChange := changes.GetPropertyChanges()[0]
3625+
assert.Equal(t, "exclusiveMaximum", exclusiveMaxChange.Property)
3626+
assert.Equal(t, Modified, exclusiveMaxChange.ChangeType)
3627+
3628+
// Test the values are correct
3629+
assert.Equal(t, "100", exclusiveMaxChange.Original)
3630+
assert.Equal(t, "200", exclusiveMaxChange.New)
3631+
}
3632+
35943633
func TestCompareSchemas_CheckXML(t *testing.T) {
35953634
// Clear hash cache to ensure deterministic results in concurrent test environments
35963635
low.ClearHashCache()

0 commit comments

Comments
 (0)