mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 12:37:48 +00:00
fix: continued moving everything to orderedmaps plus cleaned up most the tests
This commit is contained in:
@@ -4,8 +4,11 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"strings"
|
||||
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/orderedmap"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// ExtensionChanges represents any changes to custom extensions defined for an OpenAPI object.
|
||||
@@ -34,24 +37,24 @@ func (e *ExtensionChanges) TotalBreakingChanges() int {
|
||||
//
|
||||
// A current limitation relates to extensions being objects and a property of the object changes,
|
||||
// there is currently no support for knowing anything changed - so it is ignored.
|
||||
func CompareExtensions(l, r map[low.KeyReference[string]]low.ValueReference[any]) *ExtensionChanges {
|
||||
|
||||
func CompareExtensions(l, r *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]) *ExtensionChanges {
|
||||
// look at the original and then look through the new.
|
||||
seenLeft := make(map[string]*low.ValueReference[any])
|
||||
seenRight := make(map[string]*low.ValueReference[any])
|
||||
for i := range l {
|
||||
h := l[i]
|
||||
seenLeft[strings.ToLower(i.Value)] = &h
|
||||
seenLeft := make(map[string]*low.ValueReference[*yaml.Node])
|
||||
seenRight := make(map[string]*low.ValueReference[*yaml.Node])
|
||||
|
||||
for pair := orderedmap.First(l); pair != nil; pair = pair.Next() {
|
||||
h := pair.Value()
|
||||
seenLeft[strings.ToLower(pair.Key().Value)] = &h
|
||||
}
|
||||
for i := range r {
|
||||
h := r[i]
|
||||
seenRight[strings.ToLower(i.Value)] = &h
|
||||
for pair := orderedmap.First(r); pair != nil; pair = pair.Next() {
|
||||
h := pair.Value()
|
||||
seenRight[strings.ToLower(pair.Key().Value)] = &h
|
||||
}
|
||||
|
||||
var changes []*Change
|
||||
for i := range seenLeft {
|
||||
|
||||
CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true)
|
||||
CheckForObjectAdditionOrRemoval[*yaml.Node](seenLeft, seenRight, i, &changes, false, true)
|
||||
|
||||
if seenRight[i] != nil {
|
||||
var props []*PropertyCheck
|
||||
@@ -72,7 +75,7 @@ func CompareExtensions(l, r map[low.KeyReference[string]]low.ValueReference[any]
|
||||
}
|
||||
for i := range seenRight {
|
||||
if seenLeft[i] == nil {
|
||||
CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true)
|
||||
CheckForObjectAdditionOrRemoval[*yaml.Node](seenLeft, seenRight, i, &changes, false, true)
|
||||
}
|
||||
}
|
||||
ex := new(ExtensionChanges)
|
||||
@@ -86,11 +89,11 @@ func CompareExtensions(l, r map[low.KeyReference[string]]low.ValueReference[any]
|
||||
// CheckExtensions is a helper method to un-pack a left and right model that contains extensions. Once unpacked
|
||||
// the extensions are compared and returns a pointer to ExtensionChanges. If nothing changed, nil is returned.
|
||||
func CheckExtensions[T low.HasExtensions[T]](l, r T) *ExtensionChanges {
|
||||
var lExt, rExt map[low.KeyReference[string]]low.ValueReference[any]
|
||||
if len(l.GetExtensions()) > 0 {
|
||||
var lExt, rExt *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
|
||||
if orderedmap.Len(l.GetExtensions()) > 0 {
|
||||
lExt = l.GetExtensions()
|
||||
}
|
||||
if len(r.GetExtensions()) > 0 {
|
||||
if orderedmap.Len(r.GetExtensions()) > 0 {
|
||||
rExt = r.GetExtensions()
|
||||
}
|
||||
return CompareExtensions(lExt, rExt)
|
||||
|
||||
Reference in New Issue
Block a user