mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 04:20:17 +00:00
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:
@@ -4,79 +4,79 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||
)
|
||||
|
||||
// ExternalDocChanges represents changes made to any ExternalDoc object from an OpenAPI document.
|
||||
type ExternalDocChanges struct {
|
||||
*PropertyChanges
|
||||
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
|
||||
*PropertyChanges
|
||||
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
|
||||
}
|
||||
|
||||
// GetAllChanges returns a slice of all changes made between Example objects
|
||||
func (e *ExternalDocChanges) GetAllChanges() []*Change {
|
||||
var changes []*Change
|
||||
changes = append(changes, e.Changes...)
|
||||
if e.ExtensionChanges != nil {
|
||||
changes = append(changes, e.ExtensionChanges.GetAllChanges()...)
|
||||
}
|
||||
return changes
|
||||
var changes []*Change
|
||||
changes = append(changes, e.Changes...)
|
||||
if e.ExtensionChanges != nil {
|
||||
changes = append(changes, e.ExtensionChanges.GetAllChanges()...)
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
// TotalChanges returns a count of everything that changed
|
||||
func (e *ExternalDocChanges) TotalChanges() int {
|
||||
c := e.PropertyChanges.TotalChanges()
|
||||
if e.ExtensionChanges != nil {
|
||||
c += e.ExtensionChanges.TotalChanges()
|
||||
}
|
||||
return c
|
||||
c := e.PropertyChanges.TotalChanges()
|
||||
if e.ExtensionChanges != nil {
|
||||
c += e.ExtensionChanges.TotalChanges()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// TotalBreakingChanges always returns 0 for ExternalDoc objects, they are non-binding.
|
||||
func (e *ExternalDocChanges) TotalBreakingChanges() int {
|
||||
return 0
|
||||
return 0
|
||||
}
|
||||
|
||||
// CompareExternalDocs will compare a left (original) and a right (new) slice of ValueReference
|
||||
// nodes for any changes between them. If there are changes, then a pointer to ExternalDocChanges
|
||||
// is returned, otherwise if nothing changed - then nil is returned.
|
||||
func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges {
|
||||
var changes []*Change
|
||||
var props []*PropertyCheck
|
||||
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: false,
|
||||
Original: l,
|
||||
New: r,
|
||||
})
|
||||
// URL
|
||||
props = append(props, &PropertyCheck{
|
||||
LeftNode: l.URL.ValueNode,
|
||||
RightNode: r.URL.ValueNode,
|
||||
Label: v3.URLLabel,
|
||||
Changes: &changes,
|
||||
Breaking: false,
|
||||
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,
|
||||
})
|
||||
// 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)
|
||||
// check everything.
|
||||
CheckProperties(props)
|
||||
|
||||
dc := new(ExternalDocChanges)
|
||||
dc.PropertyChanges = NewPropertyChanges(changes)
|
||||
dc := new(ExternalDocChanges)
|
||||
dc.PropertyChanges = NewPropertyChanges(changes)
|
||||
|
||||
// check extensions
|
||||
dc.ExtensionChanges = CheckExtensions(l, r)
|
||||
if dc.TotalChanges() <= 0 {
|
||||
return nil
|
||||
}
|
||||
return dc
|
||||
// check extensions
|
||||
dc.ExtensionChanges = CheckExtensions(l, r)
|
||||
if dc.TotalChanges() <= 0 {
|
||||
return nil
|
||||
}
|
||||
return dc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user