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:
Dave Shanley
2023-01-05 16:20:18 -05:00
parent e6a059750b
commit f269259fcf
4 changed files with 113 additions and 11 deletions

View File

@@ -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