mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 20:47:45 +00:00
what-changed operational
the code is working, the tests are passing. There is a lot more to check, but it's a good time to bring the feature into main.
This commit is contained in:
@@ -4,8 +4,11 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||
"github.com/pb33f/libopenapi/utils"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// ExampleChanges represent changes to an Example object, part of an OpenAPI specification.
|
||||
@@ -60,16 +63,56 @@ func CompareExamples(l, r *base.Example) *ExampleChanges {
|
||||
})
|
||||
|
||||
// Value
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.Value.ValueNode,
|
||||
RightNode: r.Value.ValueNode,
|
||||
Label: v3.ValueLabel,
|
||||
Changes: &changes,
|
||||
Breaking: false,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
|
||||
if utils.IsNodeMap(l.Value.ValueNode) && utils.IsNodeMap(r.Value.ValueNode) {
|
||||
lKeys := make([]string, len(l.Value.ValueNode.Content)/2)
|
||||
rKeys := make([]string, len(r.Value.ValueNode.Content)/2)
|
||||
z := 0
|
||||
for k := range l.Value.ValueNode.Content {
|
||||
if k%2 == 0 {
|
||||
lKeys[z] = fmt.Sprintf("%v-%v", l.Value.ValueNode.Content[k].Value, l.Value.ValueNode.Content[k+1].Value)
|
||||
z++
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
z = 0
|
||||
for k := range r.Value.ValueNode.Content {
|
||||
if k%2 == 0 {
|
||||
rKeys[z] = fmt.Sprintf("%v-%v", r.Value.ValueNode.Content[k].Value, r.Value.ValueNode.Content[k+1].Value)
|
||||
z++
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
sort.Strings(lKeys)
|
||||
sort.Strings(rKeys)
|
||||
if (len(lKeys) > len(rKeys)) || (len(rKeys) > len(lKeys)) {
|
||||
CreateChange(&changes, Modified, v3.ValueLabel,
|
||||
l.Value.GetValueNode(), r.Value.GetValueNode(), false, l.Value.GetValue(), r.Value.GetValue())
|
||||
}
|
||||
for k := range lKeys {
|
||||
if lKeys[k] != rKeys[k] {
|
||||
CreateChange(&changes, Modified, v3.ValueLabel,
|
||||
l.Value.GetValueNode(), r.Value.GetValueNode(), false, l.Value.GetValue(), r.Value.GetValue())
|
||||
}
|
||||
}
|
||||
for k := range rKeys {
|
||||
if k >= len(lKeys) {
|
||||
CreateChange(&changes, Modified, v3.ValueLabel,
|
||||
nil, r.Value.GetValueNode(), false, nil, r.Value.GetValue())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.Value.ValueNode,
|
||||
RightNode: r.Value.ValueNode,
|
||||
Label: v3.ValueLabel,
|
||||
Changes: &changes,
|
||||
Breaking: false,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
}
|
||||
// ExternalValue
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.ExternalValue.ValueNode,
|
||||
|
||||
Reference in New Issue
Block a user