Skip to content

Commit

Permalink
Fix enum comparison by looking on the definitive value (without style)
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Lasne authored and daveshanley committed Jan 22, 2025
1 parent 475b40d commit baf52c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions what-changed/model/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,10 @@ func checkSchemaPropertyChanges(
j = make(map[string]int)
k = make(map[string]int)
for i := range lSchema.Enum.Value {
j[toString(lSchema.Enum.Value[i].Value)] = i
j[toString(lSchema.Enum.Value[i].Value.Value)] = i
}
for i := range rSchema.Enum.Value {
k[toString(rSchema.Enum.Value[i].Value)] = i
k[toString(rSchema.Enum.Value[i].Value.Value)] = i
}
for g := range k {
if _, ok := j[g]; !ok {
Expand Down
23 changes: 23 additions & 0 deletions what-changed/model/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,29 @@ components:
assert.Equal(t, v3.RequiredLabel, changes.Changes[0].Property)
}

func TestCompareSchemas_EnumSimilar(t *testing.T) {
left := `openapi: 3.0
components:
schemas:
OK:
enum: [a]`

right := `openapi: 3.0
components:
schemas:
OK:
enum: ["a"]`

leftDoc, rightDoc := test_BuildDoc(left, right)

// extract left reference schema and non reference schema.
lSchemaProxy := leftDoc.Components.Value.FindSchema("OK").Value
rSchemaProxy := rightDoc.Components.Value.FindSchema("OK").Value

changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.Nil(t, changes)
}

func TestCompareSchemas_EnumAdded(t *testing.T) {
left := `openapi: 3.0
components:
Expand Down

0 comments on commit baf52c9

Please sign in to comment.