mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 20:47:45 +00:00
Added server variable to what changed.
This commit is contained in:
@@ -2,3 +2,73 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||
)
|
||||
|
||||
type ServerVariableChanges struct {
|
||||
PropertyChanges
|
||||
}
|
||||
|
||||
func CompareServerVariables(l, r *v3.ServerVariable) *ServerVariableChanges {
|
||||
if low.AreEqual(l, r) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var props []*PropertyCheck
|
||||
var changes []*Change
|
||||
|
||||
lValues := make(map[string]low.NodeReference[string])
|
||||
rValues := make(map[string]low.NodeReference[string])
|
||||
for i := range l.Enum {
|
||||
lValues[l.Enum[i].Value] = l.Enum[i]
|
||||
}
|
||||
for i := range r.Enum {
|
||||
rValues[r.Enum[i].Value] = r.Enum[i]
|
||||
}
|
||||
for k := range lValues {
|
||||
if _, ok := rValues[k]; !ok {
|
||||
CreateChange(&changes, ObjectRemoved, v3.EnumLabel,
|
||||
lValues[k].ValueNode, nil, true,
|
||||
lValues[k].Value, nil)
|
||||
continue
|
||||
}
|
||||
}
|
||||
for k := range rValues {
|
||||
if _, ok := lValues[k]; !ok {
|
||||
CreateChange(&changes, ObjectAdded, v3.EnumLabel,
|
||||
lValues[k].ValueNode, rValues[k].ValueNode, false,
|
||||
lValues[k].Value, rValues[k].Value)
|
||||
}
|
||||
}
|
||||
|
||||
// default
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.Default.ValueNode,
|
||||
RightNode: r.Default.ValueNode,
|
||||
Label: v3.DefaultLabel,
|
||||
Changes: &changes,
|
||||
Breaking: true,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
|
||||
// description
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.Description.ValueNode,
|
||||
RightNode: r.Description.ValueNode,
|
||||
Label: v3.DescriptionLabel,
|
||||
Changes: &changes,
|
||||
Breaking: false,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
|
||||
// check everything.
|
||||
CheckProperties(props)
|
||||
sc := new(ServerVariableChanges)
|
||||
sc.Changes = changes
|
||||
return sc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user