Added support for unevaluatedProperties as Schema and bool #118

Also ran `gofmt` across the entire project. Things need cleaning up.

Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
Dave Shanley
2023-06-15 08:58:20 -04:00
committed by quobix
parent 148822fa2a
commit c3cf5f1e38
142 changed files with 11751 additions and 11577 deletions

View File

@@ -4,79 +4,79 @@
package model
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/v3"
)
// ServerChanges represents changes found between two OpenAPI Server Objects
type ServerChanges struct {
*PropertyChanges
ServerVariableChanges map[string]*ServerVariableChanges `json:"serverVariables,omitempty" yaml:"serverVariables,omitempty"`
*PropertyChanges
ServerVariableChanges map[string]*ServerVariableChanges `json:"serverVariables,omitempty" yaml:"serverVariables,omitempty"`
}
// GetAllChanges returns a slice of all changes made between SecurityRequirement objects
func (s *ServerChanges) GetAllChanges() []*Change {
var changes []*Change
changes = append(changes, s.Changes...)
for k := range s.ServerVariableChanges {
changes = append(changes, s.ServerVariableChanges[k].GetAllChanges()...)
}
return changes
var changes []*Change
changes = append(changes, s.Changes...)
for k := range s.ServerVariableChanges {
changes = append(changes, s.ServerVariableChanges[k].GetAllChanges()...)
}
return changes
}
// TotalChanges returns total changes found between two OpenAPI Server Objects
func (s *ServerChanges) TotalChanges() int {
c := s.PropertyChanges.TotalChanges()
for k := range s.ServerVariableChanges {
c += s.ServerVariableChanges[k].TotalChanges()
}
return c
c := s.PropertyChanges.TotalChanges()
for k := range s.ServerVariableChanges {
c += s.ServerVariableChanges[k].TotalChanges()
}
return c
}
// TotalBreakingChanges returns the total number of breaking changes found between two OpenAPI Server objects.
func (s *ServerChanges) TotalBreakingChanges() int {
c := s.PropertyChanges.TotalBreakingChanges()
for k := range s.ServerVariableChanges {
c += s.ServerVariableChanges[k].TotalBreakingChanges()
}
return c
c := s.PropertyChanges.TotalBreakingChanges()
for k := range s.ServerVariableChanges {
c += s.ServerVariableChanges[k].TotalBreakingChanges()
}
return c
}
// CompareServers compares two OpenAPI Server objects for any changes. If anything is found, returns a pointer
// to a ServerChanges instance, or returns nil if nothing is found.
func CompareServers(l, r *v3.Server) *ServerChanges {
if low.AreEqual(l, r) {
return nil
}
var changes []*Change
var props []*PropertyCheck
if low.AreEqual(l, r) {
return nil
}
var changes []*Change
var props []*PropertyCheck
// URL
props = append(props, &PropertyCheck{
LeftNode: l.URL.ValueNode,
RightNode: r.URL.ValueNode,
Label: v3.URLLabel,
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,
})
// URL
props = append(props, &PropertyCheck{
LeftNode: l.URL.ValueNode,
RightNode: r.URL.ValueNode,
Label: v3.URLLabel,
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,
})
CheckProperties(props)
sc := new(ServerChanges)
sc.PropertyChanges = NewPropertyChanges(changes)
sc.ServerVariableChanges = CheckMapForChanges(l.Variables.Value, r.Variables.Value,
&changes, v3.VariablesLabel, CompareServerVariables)
CheckProperties(props)
sc := new(ServerChanges)
sc.PropertyChanges = NewPropertyChanges(changes)
sc.ServerVariableChanges = CheckMapForChanges(l.Variables.Value, r.Variables.Value,
&changes, v3.VariablesLabel, CompareServerVariables)
return sc
return sc
}