mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
fix: handle example comparison correctly. #61
examples can be anything, most commonly maps. previously `libopenapi` did not check maps correctly. Now it does. It was also creating a panic by inserting a nil pointer as the value to a map key. This has also been fixed. Examples are the only element that use this pattern for comparison.
This commit is contained in:
@@ -1074,3 +1074,86 @@ webhooks:
|
||||
assert.Equal(t, 2, extChanges.TotalChanges())
|
||||
assert.Equal(t, 0, extChanges.TotalBreakingChanges())
|
||||
}
|
||||
|
||||
func TestCompareDocuments_OpenAPIExampleMapChanges(t *testing.T) {
|
||||
left := `openapi: 3.0.0
|
||||
paths:
|
||||
/:
|
||||
post:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
examples:
|
||||
test:
|
||||
value:
|
||||
map:
|
||||
deep:
|
||||
date: 2020-01-01`
|
||||
|
||||
right := `openapi: 3.0.0
|
||||
paths:
|
||||
/:
|
||||
post:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
examples:
|
||||
test:
|
||||
value:
|
||||
map:
|
||||
deep:
|
||||
date: "2020-01-04"`
|
||||
|
||||
// have to build docs fully to get access to objects
|
||||
siLeft, _ := datamodel.ExtractSpecInfo([]byte(left))
|
||||
siRight, _ := datamodel.ExtractSpecInfo([]byte(right))
|
||||
|
||||
lDoc, _ := v3.CreateDocument(siLeft)
|
||||
rDoc, _ := v3.CreateDocument(siRight)
|
||||
|
||||
// compare.
|
||||
extChanges := CompareDocuments(lDoc, rDoc)
|
||||
assert.Equal(t, 1, extChanges.TotalChanges())
|
||||
assert.Equal(t, 0, extChanges.TotalBreakingChanges())
|
||||
}
|
||||
|
||||
func TestCompareDocuments_OpenAPIExampleNoExampleMapChanges(t *testing.T) {
|
||||
left := `openapi: 3.0.0
|
||||
paths:
|
||||
/:
|
||||
post:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
examples:
|
||||
test:
|
||||
value:
|
||||
map:
|
||||
deep:
|
||||
date: 2020-01-01`
|
||||
|
||||
right := `openapi: 3.0.0
|
||||
paths:
|
||||
/:
|
||||
post:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
examples:
|
||||
test:
|
||||
value:
|
||||
map:
|
||||
deep:
|
||||
date: 2020-01-01`
|
||||
|
||||
// have to build docs fully to get access to objects
|
||||
siLeft, _ := datamodel.ExtractSpecInfo([]byte(left))
|
||||
siRight, _ := datamodel.ExtractSpecInfo([]byte(right))
|
||||
|
||||
lDoc, _ := v3.CreateDocument(siLeft)
|
||||
rDoc, _ := v3.CreateDocument(siRight)
|
||||
|
||||
// compare.
|
||||
extChanges := CompareDocuments(lDoc, rDoc)
|
||||
assert.Nil(t, extChanges)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user