mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
Moved what-changed PropertyChanges to a pointer in all models.
No breaking changes, gofmt seems to have gone a little nuts for some reason, but this is an internal change that moves everything to a pointer, for better reflection use down the chain.
This commit is contained in:
@@ -4,86 +4,86 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||
)
|
||||
|
||||
// EncodingChanges represent all the changes made to an Encoding object
|
||||
type EncodingChanges struct {
|
||||
PropertyChanges
|
||||
HeaderChanges map[string]*HeaderChanges `json:"headers,omitempty" yaml:"headers,omitempty"`
|
||||
*PropertyChanges
|
||||
HeaderChanges map[string]*HeaderChanges `json:"headers,omitempty" yaml:"headers,omitempty"`
|
||||
}
|
||||
|
||||
// TotalChanges returns the total number of changes made between two Encoding objects
|
||||
func (e *EncodingChanges) TotalChanges() int {
|
||||
c := e.PropertyChanges.TotalChanges()
|
||||
if e.HeaderChanges != nil {
|
||||
for i := range e.HeaderChanges {
|
||||
c += e.HeaderChanges[i].TotalChanges()
|
||||
}
|
||||
}
|
||||
return c
|
||||
c := e.PropertyChanges.TotalChanges()
|
||||
if e.HeaderChanges != nil {
|
||||
for i := range e.HeaderChanges {
|
||||
c += e.HeaderChanges[i].TotalChanges()
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// TotalBreakingChanges returns the number of changes made between two Encoding objects that were breaking.
|
||||
func (e *EncodingChanges) TotalBreakingChanges() int {
|
||||
c := e.PropertyChanges.TotalBreakingChanges()
|
||||
if e.HeaderChanges != nil {
|
||||
for i := range e.HeaderChanges {
|
||||
c += e.HeaderChanges[i].TotalBreakingChanges()
|
||||
}
|
||||
}
|
||||
return c
|
||||
c := e.PropertyChanges.TotalBreakingChanges()
|
||||
if e.HeaderChanges != nil {
|
||||
for i := range e.HeaderChanges {
|
||||
c += e.HeaderChanges[i].TotalBreakingChanges()
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// CompareEncoding returns a pointer to *EncodingChanges that contain all changes made between a left and right
|
||||
// set of Encoding objects.
|
||||
func CompareEncoding(l, r *v3.Encoding) *EncodingChanges {
|
||||
|
||||
var changes []*Change
|
||||
var props []*PropertyCheck
|
||||
var changes []*Change
|
||||
var props []*PropertyCheck
|
||||
|
||||
// ContentType
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.ContentType.ValueNode,
|
||||
RightNode: r.ContentType.ValueNode,
|
||||
Label: v3.ContentTypeLabel,
|
||||
Changes: &changes,
|
||||
Breaking: true,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
// ContentType
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.ContentType.ValueNode,
|
||||
RightNode: r.ContentType.ValueNode,
|
||||
Label: v3.ContentTypeLabel,
|
||||
Changes: &changes,
|
||||
Breaking: true,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
|
||||
// Explode
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.Explode.ValueNode,
|
||||
RightNode: r.Explode.ValueNode,
|
||||
Label: v3.ExplodeLabel,
|
||||
Changes: &changes,
|
||||
Breaking: true,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
// Explode
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.Explode.ValueNode,
|
||||
RightNode: r.Explode.ValueNode,
|
||||
Label: v3.ExplodeLabel,
|
||||
Changes: &changes,
|
||||
Breaking: true,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
|
||||
// AllowReserved
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.AllowReserved.ValueNode,
|
||||
RightNode: r.AllowReserved.ValueNode,
|
||||
Label: v3.AllowReservedLabel,
|
||||
Changes: &changes,
|
||||
Breaking: false,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
// AllowReserved
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.AllowReserved.ValueNode,
|
||||
RightNode: r.AllowReserved.ValueNode,
|
||||
Label: v3.AllowReservedLabel,
|
||||
Changes: &changes,
|
||||
Breaking: false,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
|
||||
// check everything.
|
||||
CheckProperties(props)
|
||||
ec := new(EncodingChanges)
|
||||
// check everything.
|
||||
CheckProperties(props)
|
||||
ec := new(EncodingChanges)
|
||||
|
||||
// headers
|
||||
ec.HeaderChanges = CheckMapForChanges(l.Headers.Value, r.Headers.Value, &changes, v3.HeadersLabel, CompareHeadersV3)
|
||||
ec.Changes = changes
|
||||
if ec.TotalChanges() <= 0 {
|
||||
return nil
|
||||
}
|
||||
return ec
|
||||
// headers
|
||||
ec.HeaderChanges = CheckMapForChanges(l.Headers.Value, r.Headers.Value, &changes, v3.HeadersLabel, CompareHeadersV3)
|
||||
ec.PropertyChanges = NewPropertyChanges(changes)
|
||||
if ec.TotalChanges() <= 0 {
|
||||
return nil
|
||||
}
|
||||
return ec
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user