mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 20:47:45 +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:
@@ -5,6 +5,7 @@ package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -250,7 +251,12 @@ func CheckMapForChangesWithComp[T any, R any](expLeft, expRight map[low.KeyRefer
|
||||
// run comparison.
|
||||
if compare {
|
||||
chLock.Lock()
|
||||
expChanges[k] = compareFunc(p[k].Value, h[k].Value)
|
||||
ch := compareFunc(p[k].Value, h[k].Value)
|
||||
// incorrect map results were being generated causing panics.
|
||||
// https://github.com/pb33f/libopenapi/issues/61
|
||||
if !reflect.ValueOf(&ch).Elem().IsZero() {
|
||||
expChanges[k] = ch
|
||||
}
|
||||
chLock.Unlock()
|
||||
}
|
||||
doneChan <- true
|
||||
|
||||
Reference in New Issue
Block a user