Refactoring the what-changed again

I cannot pull these models apart, they are too inter-connected and imports will cycle.
This commit is contained in:
Dave Shanley
2022-10-23 12:14:31 -04:00
parent 1197562438
commit fcd4a0f57d
36 changed files with 407 additions and 372 deletions

View File

@@ -4,10 +4,13 @@
package v2 package v2
import ( import (
"crypto/sha256"
"fmt"
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index" "github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils" "github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"strings"
) )
// Header Represents a low-level Swagger / OpenAPI 2 Header object. // Header Represents a low-level Swagger / OpenAPI 2 Header object.
@@ -86,6 +89,51 @@ func (h *Header) Build(root *yaml.Node, idx *index.SpecIndex) error {
return nil return nil
} }
// Hash will return a consistent SHA256 Hash of the Header object
func (h *Header) Hash() [32]byte {
var f []string
if h.Description.Value != "" {
f = append(f, h.Description.Value)
}
if h.Type.Value != "" {
f = append(f, h.Type.Value)
}
if h.Format.Value != "" {
f = append(f, h.Format.Value)
}
if h.CollectionFormat.Value != "" {
f = append(f, h.CollectionFormat.Value)
}
if h.Default.Value != "" {
f = append(f, fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint(h.Default.Value)))))
}
f = append(f, fmt.Sprint(h.Maximum.Value))
f = append(f, fmt.Sprint(h.Minimum.Value))
f = append(f, fmt.Sprint(h.ExclusiveMinimum.Value))
f = append(f, fmt.Sprint(h.ExclusiveMaximum.Value))
f = append(f, fmt.Sprint(h.MinLength.Value))
f = append(f, fmt.Sprint(h.MaxLength.Value))
f = append(f, fmt.Sprint(h.MinItems.Value))
f = append(f, fmt.Sprint(h.MaxItems.Value))
f = append(f, fmt.Sprint(h.MultipleOf.Value))
f = append(f, fmt.Sprint(h.UniqueItems.Value))
if h.Pattern.Value != "" {
f = append(f, fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint(h.Pattern.Value)))))
}
if len(h.Enum.Value) > 0 {
for k := range h.Enum.Value {
f = append(f, fmt.Sprint(h.Enum.Value[k].Value))
}
}
for k := range h.Extensions {
f = append(f, fmt.Sprintf("%s-%v", k.Value, h.Extensions[k].Value))
}
if h.Items.Value != nil {
f = append(f, fmt.Sprintf("%x", h.Items.Value.Hash()))
}
return sha256.Sum256([]byte(strings.Join(f, "|")))
}
// IsHeader compliance methods // IsHeader compliance methods
func (h *Header) GetType() *low.NodeReference[string] { func (h *Header) GetType() *low.NodeReference[string] {

View File

@@ -4,10 +4,12 @@
package v3 package v3
import ( import (
"crypto/sha256"
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index" "github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils" "github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"strings"
) )
// SecurityScheme represents a low-level OpenAPI 3+ SecurityScheme object. // SecurityScheme represents a low-level OpenAPI 3+ SecurityScheme object.
@@ -68,6 +70,11 @@ func (ss *SecurityScheme) Build(root *yaml.Node, idx *index.SpecIndex) error {
return nil return nil
} }
func (ss *SecurityScheme) Hash() [32]byte {
var f []string
return sha256.Sum256([]byte(strings.Join(f, "|")))
}
// FindRequirement will attempt to locate a security requirement string from a supplied name. // FindRequirement will attempt to locate a security requirement string from a supplied name.
func (sr *SecurityRequirement) FindRequirement(name string) []low.ValueReference[string] { func (sr *SecurityRequirement) FindRequirement(name string) []low.ValueReference[string] {
for _, r := range sr.ValueRequirements { for _, r := range sr.ValueRequirements {

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley // Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
package core package model
import ( import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"

View File

@@ -1,7 +1,7 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley // Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
package core package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"

View File

@@ -6,12 +6,11 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
// ContactChanges Represent changes to a Contact object that is a child of Info, part of an OpenAPI document. // ContactChanges Represent changes to a Contact object that is a child of Info, part of an OpenAPI document.
type ContactChanges struct { type ContactChanges struct {
core.PropertyChanges PropertyChanges
} }
// TotalChanges represents the total number of changes that have occurred to a Contact object // TotalChanges represents the total number of changes that have occurred to a Contact object
@@ -29,11 +28,11 @@ func (c *ContactChanges) TotalBreakingChanges() int {
// returns nil. // returns nil.
func CompareContact(l, r *base.Contact) *ContactChanges { func CompareContact(l, r *base.Contact) *ContactChanges {
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
// check URL // check URL
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.URL.ValueNode, LeftNode: l.URL.ValueNode,
RightNode: r.URL.ValueNode, RightNode: r.URL.ValueNode,
Label: v3.URLLabel, Label: v3.URLLabel,
@@ -44,7 +43,7 @@ func CompareContact(l, r *base.Contact) *ContactChanges {
}) })
// check name // check name
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Name.ValueNode, LeftNode: l.Name.ValueNode,
RightNode: r.Name.ValueNode, RightNode: r.Name.ValueNode,
Label: v3.NameLabel, Label: v3.NameLabel,
@@ -55,7 +54,7 @@ func CompareContact(l, r *base.Contact) *ContactChanges {
}) })
// check email // check email
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Email.ValueNode, LeftNode: l.Email.ValueNode,
RightNode: r.Email.ValueNode, RightNode: r.Email.ValueNode,
Label: v3.EmailLabel, Label: v3.EmailLabel,
@@ -66,7 +65,7 @@ func CompareContact(l, r *base.Contact) *ContactChanges {
}) })
// check everything. // check everything.
core.CheckProperties(props) CheckProperties(props)
dc := new(ContactChanges) dc := new(ContactChanges)
dc.Changes = changes dc.Changes = changes

View File

@@ -6,7 +6,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base" lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -34,7 +33,7 @@ url: https://pb33f.io`
// compare. // compare.
extChanges := CompareContact(&lDoc, &rDoc) extChanges := CompareContact(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
@@ -60,7 +59,7 @@ url: https://pb33f.io`
// compare. // compare.
extChanges := CompareContact(&lDoc, &rDoc) extChanges := CompareContact(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }
@@ -86,7 +85,7 @@ name: buckaroo`
// compare. // compare.
extChanges := CompareContact(&lDoc, &rDoc) extChanges := CompareContact(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
@@ -112,7 +111,7 @@ name: buckaroo`
// compare. // compare.
extChanges := CompareContact(&lDoc, &rDoc) extChanges := CompareContact(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareContact_EmailAdded(t *testing.T) { func TestCompareContact_EmailAdded(t *testing.T) {
@@ -137,7 +136,7 @@ email: buckaroo@pb33f.io`
// compare. // compare.
extChanges := CompareContact(&lDoc, &rDoc) extChanges := CompareContact(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
@@ -163,7 +162,7 @@ email: buckaroo@pb33f.io`
// compare. // compare.
extChanges := CompareContact(&lDoc, &rDoc) extChanges := CompareContact(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareContact_EmailModified(t *testing.T) { func TestCompareContact_EmailModified(t *testing.T) {
@@ -189,7 +188,7 @@ email: dave@quobix.com`
// compare. // compare.
extChanges := CompareContact(&lDoc, &rDoc) extChanges := CompareContact(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
} }

View File

@@ -6,13 +6,12 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
// DiscriminatorChanges represents changes made to a Discriminator OpenAPI object // DiscriminatorChanges represents changes made to a Discriminator OpenAPI object
type DiscriminatorChanges struct { type DiscriminatorChanges struct {
core.PropertyChanges PropertyChanges
MappingChanges []*core.Change MappingChanges []*Change
} }
// TotalChanges returns a count of everything changed within the Discriminator object // TotalChanges returns a count of everything changed within the Discriminator object
@@ -29,19 +28,19 @@ func (d *DiscriminatorChanges) TotalChanges() int {
// TotalBreakingChanges returns the number of breaking changes made by the Discriminator // TotalBreakingChanges returns the number of breaking changes made by the Discriminator
func (d *DiscriminatorChanges) TotalBreakingChanges() int { func (d *DiscriminatorChanges) TotalBreakingChanges() int {
return d.PropertyChanges.TotalBreakingChanges() + core.CountBreakingChanges(d.MappingChanges) return d.PropertyChanges.TotalBreakingChanges() + CountBreakingChanges(d.MappingChanges)
} }
// CompareDiscriminator will check a left (original) and right (new) Discriminator object for changes // CompareDiscriminator will check a left (original) and right (new) Discriminator object for changes
// and will return a pointer to DiscriminatorChanges // and will return a pointer to DiscriminatorChanges
func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges { func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges {
dc := new(DiscriminatorChanges) dc := new(DiscriminatorChanges)
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
var mappingChanges []*core.Change var mappingChanges []*Change
// Name (breaking change) // Name (breaking change)
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.PropertyName.ValueNode, LeftNode: l.PropertyName.ValueNode,
RightNode: r.PropertyName.ValueNode, RightNode: r.PropertyName.ValueNode,
Label: v3.PropertyNameLabel, Label: v3.PropertyNameLabel,
@@ -52,19 +51,19 @@ func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges {
}) })
// check properties // check properties
core.CheckProperties(props) CheckProperties(props)
// flatten maps // flatten maps
lMap := core.FlattenLowLevelMap[string](l.Mapping) lMap := FlattenLowLevelMap[string](l.Mapping)
rMap := core.FlattenLowLevelMap[string](r.Mapping) rMap := FlattenLowLevelMap[string](r.Mapping)
// check for removals, modifications and moves // check for removals, modifications and moves
for i := range lMap { for i := range lMap {
core.CheckForObjectAdditionOrRemoval[string](lMap, rMap, i, &mappingChanges, false, true) CheckForObjectAdditionOrRemoval[string](lMap, rMap, i, &mappingChanges, false, true)
// if the existing tag exists, let's check it. // if the existing tag exists, let's check it.
if rMap[i] != nil { if rMap[i] != nil {
if lMap[i].Value != rMap[i].Value { if lMap[i].Value != rMap[i].Value {
core.CreateChange(&mappingChanges, core.Modified, i, lMap[i].GetValueNode(), CreateChange(&mappingChanges, Modified, i, lMap[i].GetValueNode(),
rMap[i].GetValueNode(), true, lMap[i].GetValue(), rMap[i].GetValue()) rMap[i].GetValueNode(), true, lMap[i].GetValue(), rMap[i].GetValue())
} }
} }
@@ -72,7 +71,7 @@ func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges {
for i := range rMap { for i := range rMap {
if lMap[i] == nil { if lMap[i] == nil {
core.CreateChange(&mappingChanges, core.ObjectAdded, i, nil, CreateChange(&mappingChanges, ObjectAdded, i, nil,
rMap[i].GetValueNode(), false, nil, rMap[i].GetValue()) rMap[i].GetValueNode(), false, nil, rMap[i].GetValue())
} }
} }

View File

@@ -6,7 +6,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -31,7 +30,7 @@ func TestCompareDiscriminator_PropertyNameChanged(t *testing.T) {
// compare. // compare.
extChanges := CompareDiscriminator(&lDoc, &rDoc) extChanges := CompareDiscriminator(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
} }
@@ -54,7 +53,7 @@ func TestCompareDiscriminator_PropertyNameRemoved(t *testing.T) {
// compare. // compare.
extChanges := CompareDiscriminator(&lDoc, &rDoc) extChanges := CompareDiscriminator(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareDiscriminator_PropertyNameAdded(t *testing.T) { func TestCompareDiscriminator_PropertyNameAdded(t *testing.T) {
@@ -76,7 +75,7 @@ func TestCompareDiscriminator_PropertyNameAdded(t *testing.T) {
// compare. // compare.
extChanges := CompareDiscriminator(&lDoc, &rDoc) extChanges := CompareDiscriminator(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareDiscriminator_MappingAdded(t *testing.T) { func TestCompareDiscriminator_MappingAdded(t *testing.T) {
@@ -103,7 +102,7 @@ mapping:
assert.Equal(t, 2, extChanges.TotalChanges()) assert.Equal(t, 2, extChanges.TotalChanges())
for _, k := range extChanges.MappingChanges { for _, k := range extChanges.MappingChanges {
assert.Equal(t, core.ObjectAdded, k.ChangeType) assert.Equal(t, ObjectAdded, k.ChangeType)
if k.Property == "chuffing" { if k.Property == "chuffing" {
assert.Equal(t, "puffing", k.New) assert.Equal(t, "puffing", k.New)
} }
@@ -137,7 +136,7 @@ mapping:
// compare. // compare.
extChanges := CompareDiscriminator(&lDoc, &rDoc) extChanges := CompareDiscriminator(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.MappingChanges[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.MappingChanges[0].ChangeType)
assert.Equal(t, "chuffing", extChanges.MappingChanges[0].Property) assert.Equal(t, "chuffing", extChanges.MappingChanges[0].Property)
assert.Equal(t, "puffing", extChanges.MappingChanges[0].Original) assert.Equal(t, "puffing", extChanges.MappingChanges[0].Original)
} }
@@ -166,7 +165,7 @@ mapping:
// compare. // compare.
extChanges := CompareDiscriminator(&lDoc, &rDoc) extChanges := CompareDiscriminator(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.ObjectAdded, extChanges.MappingChanges[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.MappingChanges[0].ChangeType)
assert.Equal(t, "hacking", extChanges.MappingChanges[0].Property) assert.Equal(t, "hacking", extChanges.MappingChanges[0].Property)
assert.Equal(t, "coding", extChanges.MappingChanges[0].New) assert.Equal(t, "coding", extChanges.MappingChanges[0].New)
@@ -197,10 +196,10 @@ mapping:
// compare. // compare.
extChanges := CompareDiscriminator(&lDoc, &rDoc) extChanges := CompareDiscriminator(&lDoc, &rDoc)
assert.Equal(t, 2, extChanges.TotalChanges()) assert.Equal(t, 2, extChanges.TotalChanges())
assert.Equal(t, core.ObjectAdded, extChanges.MappingChanges[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.MappingChanges[0].ChangeType)
for _, k := range extChanges.MappingChanges { for _, k := range extChanges.MappingChanges {
assert.Equal(t, core.ObjectAdded, k.ChangeType) assert.Equal(t, ObjectAdded, k.ChangeType)
if k.Property == "hacking" { if k.Property == "hacking" {
assert.Equal(t, "coding", k.New) assert.Equal(t, "coding", k.New)
} }
@@ -233,7 +232,7 @@ mapping:
// compare. // compare.
extChanges := CompareDiscriminator(&lDoc, &rDoc) extChanges := CompareDiscriminator(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.MappingChanges[0].ChangeType) assert.Equal(t, Modified, extChanges.MappingChanges[0].ChangeType)
assert.Equal(t, "chuffing", extChanges.MappingChanges[0].Property) assert.Equal(t, "chuffing", extChanges.MappingChanges[0].Property)
assert.Equal(t, "herbs", extChanges.MappingChanges[0].New) assert.Equal(t, "herbs", extChanges.MappingChanges[0].New)
assert.Equal(t, "puffing", extChanges.MappingChanges[0].Original) assert.Equal(t, "puffing", extChanges.MappingChanges[0].Original)

View File

@@ -5,7 +5,6 @@ package model
import ( import (
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
type EncodingChanges struct { type EncodingChanges struct {
@@ -35,11 +34,11 @@ func (e *EncodingChanges) TotalBreakingChanges() int {
func CompareEncoding(l, r *v3.Encoding) *EncodingChanges { func CompareEncoding(l, r *v3.Encoding) *EncodingChanges {
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
// ContentType // ContentType
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.ContentType.ValueNode, LeftNode: l.ContentType.ValueNode,
RightNode: r.ContentType.ValueNode, RightNode: r.ContentType.ValueNode,
Label: v3.ContentTypeLabel, Label: v3.ContentTypeLabel,
@@ -50,7 +49,7 @@ func CompareEncoding(l, r *v3.Encoding) *EncodingChanges {
}) })
// Explode // Explode
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Explode.ValueNode, LeftNode: l.Explode.ValueNode,
RightNode: r.Explode.ValueNode, RightNode: r.Explode.ValueNode,
Label: v3.ExplodeLabel, Label: v3.ExplodeLabel,
@@ -61,7 +60,7 @@ func CompareEncoding(l, r *v3.Encoding) *EncodingChanges {
}) })
// AllowReserved // AllowReserved
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.AllowReserved.ValueNode, LeftNode: l.AllowReserved.ValueNode,
RightNode: r.AllowReserved.ValueNode, RightNode: r.AllowReserved.ValueNode,
Label: v3.AllowReservedLabel, Label: v3.AllowReservedLabel,
@@ -72,11 +71,11 @@ func CompareEncoding(l, r *v3.Encoding) *EncodingChanges {
}) })
// check everything. // check everything.
core.CheckProperties(props) CheckProperties(props)
ec := new(EncodingChanges) ec := new(EncodingChanges)
// headers // headers
ec.HeaderChanges = core.CheckMapForChanges(l.Headers.Value, r.Headers.Value, &changes, v3.HeadersLabel, CompareHeadersV3) ec.HeaderChanges = CheckMapForChanges(l.Headers.Value, r.Headers.Value, &changes, v3.HeadersLabel, CompareHeadersV3)
ec.Changes = changes ec.Changes = changes
if ec.TotalChanges() <= 0 { if ec.TotalChanges() <= 0 {
return nil return nil

View File

@@ -6,7 +6,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -116,7 +115,7 @@ allowReserved: true`
assert.NotNil(t, extChanges) assert.NotNil(t, extChanges)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.HeadersLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.HeadersLabel, extChanges.Changes[0].Property)
} }

View File

@@ -6,12 +6,11 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
// ExampleChanges represent changes to an Example object, part of an OpenAPI specification. // ExampleChanges represent changes to an Example object, part of an OpenAPI specification.
type ExampleChanges struct { type ExampleChanges struct {
core.PropertyChanges PropertyChanges
ExtensionChanges *ExtensionChanges ExtensionChanges *ExtensionChanges
} }
@@ -35,11 +34,11 @@ func (e *ExampleChanges) TotalBreakingChanges() int {
func CompareExamples(l, r *base.Example) *ExampleChanges { func CompareExamples(l, r *base.Example) *ExampleChanges {
ec := new(ExampleChanges) ec := new(ExampleChanges)
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
// Summary // Summary
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Summary.ValueNode, LeftNode: l.Summary.ValueNode,
RightNode: r.Summary.ValueNode, RightNode: r.Summary.ValueNode,
Label: v3.SummaryLabel, Label: v3.SummaryLabel,
@@ -50,7 +49,7 @@ func CompareExamples(l, r *base.Example) *ExampleChanges {
}) })
// Description // Description
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Description.ValueNode, LeftNode: l.Description.ValueNode,
RightNode: r.Description.ValueNode, RightNode: r.Description.ValueNode,
Label: v3.DescriptionLabel, Label: v3.DescriptionLabel,
@@ -61,7 +60,7 @@ func CompareExamples(l, r *base.Example) *ExampleChanges {
}) })
// Value // Value
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Value.ValueNode, LeftNode: l.Value.ValueNode,
RightNode: r.Value.ValueNode, RightNode: r.Value.ValueNode,
Label: v3.ValueLabel, Label: v3.ValueLabel,
@@ -72,7 +71,7 @@ func CompareExamples(l, r *base.Example) *ExampleChanges {
}) })
// ExternalValue // ExternalValue
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.ExternalValue.ValueNode, LeftNode: l.ExternalValue.ValueNode,
RightNode: r.ExternalValue.ValueNode, RightNode: r.ExternalValue.ValueNode,
Label: v3.ExternalValue, Label: v3.ExternalValue,
@@ -83,7 +82,7 @@ func CompareExamples(l, r *base.Example) *ExampleChanges {
}) })
// check properties // check properties
core.CheckProperties(props) CheckProperties(props)
// check extensions // check extensions
ec.ExtensionChanges = CheckExtensions(l, r) ec.ExtensionChanges = CheckExtensions(l, r)

View File

@@ -7,7 +7,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -34,7 +33,7 @@ func TestCompareExamples_SummaryModified(t *testing.T) {
assert.Equal(t, extChanges.TotalChanges(), 1) assert.Equal(t, extChanges.TotalChanges(), 1)
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.SummaryLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.SummaryLabel, extChanges.Changes[0].Property)
assert.Equal(t, "magic herbs", extChanges.Changes[0].Original) assert.Equal(t, "magic herbs", extChanges.Changes[0].Original)
assert.Equal(t, "cure all", extChanges.Changes[0].New) assert.Equal(t, "cure all", extChanges.Changes[0].New)
@@ -61,7 +60,7 @@ description: cure all`
extChanges := CompareExamples(&lDoc, &rDoc) extChanges := CompareExamples(&lDoc, &rDoc)
assert.Equal(t, extChanges.TotalChanges(), 1) assert.Equal(t, extChanges.TotalChanges(), 1)
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.DescriptionLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.DescriptionLabel, extChanges.Changes[0].Property)
assert.Equal(t, "cure all", extChanges.Changes[0].New) assert.Equal(t, "cure all", extChanges.Changes[0].New)
} }
@@ -87,7 +86,7 @@ x-herbs: cure all`
extChanges := CompareExamples(&lDoc, &rDoc) extChanges := CompareExamples(&lDoc, &rDoc)
assert.Equal(t, extChanges.TotalChanges(), 1) assert.Equal(t, extChanges.TotalChanges(), 1)
assert.Equal(t, core.ObjectAdded, extChanges.ExtensionChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.ExtensionChanges.Changes[0].ChangeType)
assert.Equal(t, "x-herbs", extChanges.ExtensionChanges.Changes[0].Property) assert.Equal(t, "x-herbs", extChanges.ExtensionChanges.Changes[0].Property)
assert.Equal(t, "cure all", extChanges.ExtensionChanges.Changes[0].New) assert.Equal(t, "cure all", extChanges.ExtensionChanges.Changes[0].New)
} }

View File

@@ -5,13 +5,12 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/what-changed/core"
"strings" "strings"
) )
// ExtensionChanges represents any changes to custom extensions defined for an OpenAPI object. // ExtensionChanges represents any changes to custom extensions defined for an OpenAPI object.
type ExtensionChanges struct { type ExtensionChanges struct {
core.PropertyChanges PropertyChanges
} }
func (e *ExtensionChanges) TotalChanges() int { func (e *ExtensionChanges) TotalChanges() int {
@@ -43,15 +42,15 @@ func CompareExtensions(l, r map[low.KeyReference[string]]low.ValueReference[any]
seenRight[strings.ToLower(i.Value)] = &h seenRight[strings.ToLower(i.Value)] = &h
} }
var changes []*core.Change var changes []*Change
for i := range seenLeft { for i := range seenLeft {
core.CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true) CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true)
if seenRight[i] != nil { if seenRight[i] != nil {
var props []*core.PropertyCheck var props []*PropertyCheck
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: seenLeft[i].ValueNode, LeftNode: seenLeft[i].ValueNode,
RightNode: seenRight[i].ValueNode, RightNode: seenRight[i].ValueNode,
Label: i, Label: i,
@@ -62,12 +61,12 @@ func CompareExtensions(l, r map[low.KeyReference[string]]low.ValueReference[any]
}) })
// check properties // check properties
core.CheckProperties(props) CheckProperties(props)
} }
} }
for i := range seenRight { for i := range seenRight {
if seenLeft[i] == nil { if seenLeft[i] == nil {
core.CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true) CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true)
} }
} }
ex := new(ExtensionChanges) ex := new(ExtensionChanges)

View File

@@ -5,7 +5,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -26,7 +25,7 @@ func TestCompareExtensions(t *testing.T) {
extChanges := CompareExtensions(lExt, rExt) extChanges := CompareExtensions(lExt, rExt)
assert.Equal(t, extChanges.TotalChanges(), 1) assert.Equal(t, extChanges.TotalChanges(), 1)
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
assert.Equal(t, "1", extChanges.Changes[0].Original) assert.Equal(t, "1", extChanges.Changes[0].Original)
assert.Equal(t, "2", extChanges.Changes[0].New) assert.Equal(t, "2", extChanges.Changes[0].New)
assert.False(t, extChanges.Changes[0].Context.HasChanged()) assert.False(t, extChanges.Changes[0].Context.HasChanged())
@@ -50,7 +49,7 @@ x-test: 1`
extChanges := CompareExtensions(lExt, rExt) extChanges := CompareExtensions(lExt, rExt)
assert.Len(t, extChanges.Changes, 1) assert.Len(t, extChanges.Changes, 1)
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, 2, extChanges.Changes[0].Context.OriginalLine) assert.Equal(t, 2, extChanges.Changes[0].Context.OriginalLine)
assert.Equal(t, -1, extChanges.Changes[0].Context.NewLine) assert.Equal(t, -1, extChanges.Changes[0].Context.NewLine)
assert.Equal(t, "1", extChanges.Changes[0].Original) assert.Equal(t, "1", extChanges.Changes[0].Original)
@@ -74,7 +73,7 @@ x-test: 1`
extChanges := CompareExtensions(lExt, rExt) extChanges := CompareExtensions(lExt, rExt)
assert.Len(t, extChanges.Changes, 1) assert.Len(t, extChanges.Changes, 1)
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, -1, extChanges.Changes[0].Context.OriginalLine) assert.Equal(t, -1, extChanges.Changes[0].Context.OriginalLine)
assert.Equal(t, 2, extChanges.Changes[0].Context.NewLine) assert.Equal(t, 2, extChanges.Changes[0].Context.NewLine)
assert.Equal(t, "1", extChanges.Changes[0].New) assert.Equal(t, "1", extChanges.Changes[0].New)

View File

@@ -6,12 +6,11 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
// ExternalDocChanges represents changes made to any ExternalDoc object from an OpenAPI document. // ExternalDocChanges represents changes made to any ExternalDoc object from an OpenAPI document.
type ExternalDocChanges struct { type ExternalDocChanges struct {
core.PropertyChanges PropertyChanges
ExtensionChanges *ExtensionChanges ExtensionChanges *ExtensionChanges
} }
@@ -33,11 +32,11 @@ func (e *ExternalDocChanges) TotalBreakingChanges() int {
// nodes for any changes between them. If there are changes, then a pointer to ExternalDocChanges // 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. // is returned, otherwise if nothing changed - then nil is returned.
func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges { func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges {
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
// URL // URL
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.URL.ValueNode, LeftNode: l.URL.ValueNode,
RightNode: r.URL.ValueNode, RightNode: r.URL.ValueNode,
Label: v3.URLLabel, Label: v3.URLLabel,
@@ -48,7 +47,7 @@ func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges {
}) })
// description. // description.
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Description.ValueNode, LeftNode: l.Description.ValueNode,
RightNode: r.Description.ValueNode, RightNode: r.Description.ValueNode,
Label: v3.DescriptionLabel, Label: v3.DescriptionLabel,
@@ -59,7 +58,7 @@ func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges {
}) })
// check everything. // check everything.
core.CheckProperties(props) CheckProperties(props)
dc := new(ExternalDocChanges) dc := new(ExternalDocChanges)
dc.Changes = changes dc.Changes = changes

View File

@@ -7,7 +7,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base" lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3" lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -43,7 +42,7 @@ x-testing: hiya!`
// validate property changes // validate property changes
urlChange := extChanges.Changes[0] urlChange := extChanges.Changes[0]
assert.Equal(t, core.Modified, urlChange.ChangeType) assert.Equal(t, Modified, urlChange.ChangeType)
assert.False(t, urlChange.Context.HasChanged()) assert.False(t, urlChange.Context.HasChanged())
assert.Equal(t, "https://pb33f.io", urlChange.Original) assert.Equal(t, "https://pb33f.io", urlChange.Original)
assert.Equal(t, "https://quobix.com", urlChange.New) assert.Equal(t, "https://quobix.com", urlChange.New)
@@ -51,7 +50,7 @@ x-testing: hiya!`
assert.Equal(t, lowv3.URLLabel, urlChange.Property) assert.Equal(t, lowv3.URLLabel, urlChange.Property)
descChange := extChanges.Changes[1] descChange := extChanges.Changes[1]
assert.Equal(t, core.Modified, descChange.ChangeType) assert.Equal(t, Modified, descChange.ChangeType)
assert.False(t, descChange.Context.HasChanged()) assert.False(t, descChange.Context.HasChanged())
assert.Equal(t, "this is another test", descChange.New) assert.Equal(t, "this is another test", descChange.New)
assert.Equal(t, "this is a test", descChange.Original) assert.Equal(t, "this is a test", descChange.Original)
@@ -60,7 +59,7 @@ x-testing: hiya!`
// validate extensions // validate extensions
extChange := extChanges.ExtensionChanges.Changes[0] extChange := extChanges.ExtensionChanges.Changes[0]
assert.Equal(t, core.Modified, extChange.ChangeType) assert.Equal(t, Modified, extChange.ChangeType)
assert.False(t, extChange.Context.HasChanged()) assert.False(t, extChange.Context.HasChanged())
assert.Equal(t, "hiya!", extChange.New) assert.Equal(t, "hiya!", extChange.New)
assert.Equal(t, "hello", extChange.Original) assert.Equal(t, "hello", extChange.Original)
@@ -98,21 +97,21 @@ url: https://quobix.com`
// validate property changes // validate property changes
urlChange := extChanges.Changes[0] urlChange := extChanges.Changes[0]
assert.Equal(t, core.Modified, urlChange.ChangeType) assert.Equal(t, Modified, urlChange.ChangeType)
assert.True(t, urlChange.Context.HasChanged()) assert.True(t, urlChange.Context.HasChanged())
assert.Equal(t, "https://pb33f.io", urlChange.Original) assert.Equal(t, "https://pb33f.io", urlChange.Original)
assert.Equal(t, "https://quobix.com", urlChange.New) assert.Equal(t, "https://quobix.com", urlChange.New)
assert.Equal(t, lowv3.URLLabel, urlChange.Property) assert.Equal(t, lowv3.URLLabel, urlChange.Property)
descChange := extChanges.Changes[1] descChange := extChanges.Changes[1]
assert.Equal(t, core.Modified, descChange.ChangeType) assert.Equal(t, Modified, descChange.ChangeType)
assert.True(t, descChange.Context.HasChanged()) assert.True(t, descChange.Context.HasChanged())
assert.Equal(t, "this is another test", descChange.New) assert.Equal(t, "this is another test", descChange.New)
assert.Equal(t, "this is a test", descChange.Original) assert.Equal(t, "this is a test", descChange.Original)
// validate extensions // validate extensions
extChange := extChanges.ExtensionChanges.Changes[0] extChange := extChanges.ExtensionChanges.Changes[0]
assert.Equal(t, core.Modified, extChange.ChangeType) assert.Equal(t, Modified, extChange.ChangeType)
assert.True(t, extChange.Context.HasChanged()) assert.True(t, extChange.Context.HasChanged())
assert.Equal(t, "hiya!", extChange.New) assert.Equal(t, "hiya!", extChange.New)
assert.Equal(t, "hello", extChange.Original) assert.Equal(t, "hello", extChange.Original)
@@ -170,7 +169,7 @@ x-testing: hello`
// compare. // compare.
extChanges := CompareExternalDocs(&lDoc, &rDoc) extChanges := CompareExternalDocs(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareExternalDocs_URLAdded(t *testing.T) { func TestCompareExternalDocs_URLAdded(t *testing.T) {
@@ -195,7 +194,7 @@ url: https://pb33f.io`
// compare. // compare.
extChanges := CompareExternalDocs(&lDoc, &rDoc) extChanges := CompareExternalDocs(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareExternalDocs_DescriptionRemoved(t *testing.T) { func TestCompareExternalDocs_DescriptionRemoved(t *testing.T) {
@@ -220,7 +219,7 @@ description: something`
// compare. // compare.
extChanges := CompareExternalDocs(&lDoc, &rDoc) extChanges := CompareExternalDocs(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareExternalDocs_URLRemoved(t *testing.T) { func TestCompareExternalDocs_URLRemoved(t *testing.T) {
@@ -245,5 +244,5 @@ url: https://pb33f.io`
// compare // compare
extChanges := CompareExternalDocs(&lDoc, &rDoc) extChanges := CompareExternalDocs(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }

View File

@@ -7,12 +7,11 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
v2 "github.com/pb33f/libopenapi/datamodel/low/v2" v2 "github.com/pb33f/libopenapi/datamodel/low/v2"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"reflect" "reflect"
) )
type HeaderChanges struct { type HeaderChanges struct {
core.PropertyChanges PropertyChanges
SchemaChanges *SchemaChanges SchemaChanges *SchemaChanges
ExamplesChanges map[string]*ExampleChanges ExamplesChanges map[string]*ExampleChanges
ContentChanges map[string]*MediaTypeChanges ContentChanges map[string]*MediaTypeChanges
@@ -56,8 +55,8 @@ func (h *HeaderChanges) TotalBreakingChanges() int {
return c return c
} }
func addOpenAPIHeaderProperties(left, right low.IsHeader, changes *[]*core.Change) []*core.PropertyCheck { func addOpenAPIHeaderProperties(left, right low.IsHeader, changes *[]*Change) []*PropertyCheck {
var props []*core.PropertyCheck var props []*PropertyCheck
// style // style
addPropertyCheck(&props, left.GetStyle().ValueNode, right.GetStyle().ValueNode, addPropertyCheck(&props, left.GetStyle().ValueNode, right.GetStyle().ValueNode,
@@ -90,8 +89,8 @@ func addOpenAPIHeaderProperties(left, right low.IsHeader, changes *[]*core.Chang
return props return props
} }
func addSwaggerHeaderProperties(left, right low.IsHeader, changes *[]*core.Change) []*core.PropertyCheck { func addSwaggerHeaderProperties(left, right low.IsHeader, changes *[]*Change) []*PropertyCheck {
var props []*core.PropertyCheck var props []*PropertyCheck
// type // type
addPropertyCheck(&props, left.GetType().ValueNode, right.GetType().ValueNode, addPropertyCheck(&props, left.GetType().ValueNode, right.GetType().ValueNode,
@@ -152,8 +151,8 @@ func addSwaggerHeaderProperties(left, right low.IsHeader, changes *[]*core.Chang
return props return props
} }
func addCommonHeaderProperties(left, right low.IsHeader, changes *[]*core.Change) []*core.PropertyCheck { func addCommonHeaderProperties(left, right low.IsHeader, changes *[]*Change) []*PropertyCheck {
var props []*core.PropertyCheck var props []*PropertyCheck
// description // description
addPropertyCheck(&props, left.GetDescription().ValueNode, right.GetDescription().ValueNode, addPropertyCheck(&props, left.GetDescription().ValueNode, right.GetDescription().ValueNode,
@@ -172,20 +171,26 @@ func CompareHeadersV3(l, r *v3.Header) *HeaderChanges {
func CompareHeaders(l, r any) *HeaderChanges { func CompareHeaders(l, r any) *HeaderChanges {
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
hc := new(HeaderChanges) hc := new(HeaderChanges)
// handle swagger. // handle swagger.
if reflect.TypeOf(&v2.Header{}) == reflect.TypeOf(l) && reflect.TypeOf(&v2.Header{}) == reflect.TypeOf(r) { if reflect.TypeOf(&v2.Header{}) == reflect.TypeOf(l) && reflect.TypeOf(&v2.Header{}) == reflect.TypeOf(r) {
lHeader := l.(*v2.Header) lHeader := l.(*v2.Header)
rHeader := r.(*v2.Header) rHeader := r.(*v2.Header)
// perform hash check to avoid further processing
if low.AreEqual(lHeader, rHeader) {
return nil
}
props = append(props, addCommonHeaderProperties(lHeader, rHeader, &changes)...) props = append(props, addCommonHeaderProperties(lHeader, rHeader, &changes)...)
props = append(props, addSwaggerHeaderProperties(lHeader, rHeader, &changes)...) props = append(props, addSwaggerHeaderProperties(lHeader, rHeader, &changes)...)
// enum // enum
if len(lHeader.Enum.Value) > 0 || len(rHeader.Enum.Value) > 0 { if len(lHeader.Enum.Value) > 0 || len(rHeader.Enum.Value) > 0 {
core.ExtractStringValueSliceChanges(lHeader.Enum.Value, rHeader.Enum.Value, &changes, v3.EnumLabel) ExtractStringValueSliceChanges(lHeader.Enum.Value, rHeader.Enum.Value, &changes, v3.EnumLabel)
} }
// items // items
@@ -195,11 +200,11 @@ func CompareHeaders(l, r any) *HeaderChanges {
} }
} }
if lHeader.Items.IsEmpty() && !rHeader.Items.IsEmpty() { if lHeader.Items.IsEmpty() && !rHeader.Items.IsEmpty() {
core.CreateChange(&changes, core.ObjectAdded, v3.ItemsLabel, nil, CreateChange(&changes, ObjectAdded, v3.ItemsLabel, nil,
rHeader.Items.ValueNode, true, nil, rHeader.Items.Value) rHeader.Items.ValueNode, true, nil, rHeader.Items.Value)
} }
if !lHeader.Items.IsEmpty() && rHeader.Items.IsEmpty() { if !lHeader.Items.IsEmpty() && rHeader.Items.IsEmpty() {
core.CreateChange(&changes, core.ObjectRemoved, v3.SchemaLabel, lHeader.Items.ValueNode, CreateChange(&changes, ObjectRemoved, v3.SchemaLabel, lHeader.Items.ValueNode,
nil, true, lHeader.Items.Value, nil) nil, true, lHeader.Items.Value, nil)
} }
hc.ExtensionChanges = CompareExtensions(lHeader.Extensions, rHeader.Extensions) hc.ExtensionChanges = CompareExtensions(lHeader.Extensions, rHeader.Extensions)
@@ -209,6 +214,12 @@ func CompareHeaders(l, r any) *HeaderChanges {
if reflect.TypeOf(&v3.Header{}) == reflect.TypeOf(l) && reflect.TypeOf(&v3.Header{}) == reflect.TypeOf(r) { if reflect.TypeOf(&v3.Header{}) == reflect.TypeOf(l) && reflect.TypeOf(&v3.Header{}) == reflect.TypeOf(r) {
lHeader := l.(*v3.Header) lHeader := l.(*v3.Header)
rHeader := r.(*v3.Header) rHeader := r.(*v3.Header)
// perform hash check to avoid further processing
if low.AreEqual(lHeader, rHeader) {
return nil
}
props = append(props, addCommonHeaderProperties(lHeader, rHeader, &changes)...) props = append(props, addCommonHeaderProperties(lHeader, rHeader, &changes)...)
props = append(props, addOpenAPIHeaderProperties(lHeader, rHeader, &changes)...) props = append(props, addOpenAPIHeaderProperties(lHeader, rHeader, &changes)...)
@@ -218,17 +229,17 @@ func CompareHeaders(l, r any) *HeaderChanges {
} }
// examples // examples
hc.ExamplesChanges = core.CheckMapForChanges(lHeader.Examples.Value, rHeader.Examples.Value, hc.ExamplesChanges = CheckMapForChanges(lHeader.Examples.Value, rHeader.Examples.Value,
&changes, v3.ExamplesLabel, CompareExamples) &changes, v3.ExamplesLabel, CompareExamples)
// content // content
hc.ContentChanges = core.CheckMapForChanges(lHeader.Content.Value, rHeader.Content.Value, hc.ContentChanges = CheckMapForChanges(lHeader.Content.Value, rHeader.Content.Value,
&changes, v3.ContentLabel, CompareMediaTypes) &changes, v3.ContentLabel, CompareMediaTypes)
hc.ExtensionChanges = CompareExtensions(lHeader.Extensions, rHeader.Extensions) hc.ExtensionChanges = CompareExtensions(lHeader.Extensions, rHeader.Extensions)
} }
core.CheckProperties(props) CheckProperties(props)
hc.Changes = changes hc.Changes = changes
if hc.TotalChanges() <= 0 { if hc.TotalChanges() <= 0 {
return nil return nil

View File

@@ -7,7 +7,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v2"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -168,7 +167,7 @@ x-beer: yummy`
assert.NotNil(t, extChanges) assert.NotNil(t, extChanges)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareHeaders_v2_removedItems(t *testing.T) { func TestCompareHeaders_v2_removedItems(t *testing.T) {
@@ -212,7 +211,7 @@ x-beer: yummy`
assert.NotNil(t, extChanges) assert.NotNil(t, extChanges)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareHeaders_v2_ItemsModified(t *testing.T) { func TestCompareHeaders_v2_ItemsModified(t *testing.T) {

View File

@@ -6,12 +6,11 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
// InfoChanges represents the number of changes to an Info object. Part of an OpenAPI document // InfoChanges represents the number of changes to an Info object. Part of an OpenAPI document
type InfoChanges struct { type InfoChanges struct {
core.PropertyChanges PropertyChanges
ContactChanges *ContactChanges ContactChanges *ContactChanges
LicenseChanges *LicenseChanges LicenseChanges *LicenseChanges
} }
@@ -38,11 +37,11 @@ func (i *InfoChanges) TotalBreakingChanges() int {
// returned instead. // returned instead.
func CompareInfo(l, r *base.Info) *InfoChanges { func CompareInfo(l, r *base.Info) *InfoChanges {
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
// Title // Title
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Title.ValueNode, LeftNode: l.Title.ValueNode,
RightNode: r.Title.ValueNode, RightNode: r.Title.ValueNode,
Label: v3.TitleLabel, Label: v3.TitleLabel,
@@ -53,7 +52,7 @@ func CompareInfo(l, r *base.Info) *InfoChanges {
}) })
// Description // Description
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Description.ValueNode, LeftNode: l.Description.ValueNode,
RightNode: r.Description.ValueNode, RightNode: r.Description.ValueNode,
Label: v3.DescriptionLabel, Label: v3.DescriptionLabel,
@@ -64,7 +63,7 @@ func CompareInfo(l, r *base.Info) *InfoChanges {
}) })
// TermsOfService // TermsOfService
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.TermsOfService.ValueNode, LeftNode: l.TermsOfService.ValueNode,
RightNode: r.TermsOfService.ValueNode, RightNode: r.TermsOfService.ValueNode,
Label: v3.TermsOfServiceLabel, Label: v3.TermsOfServiceLabel,
@@ -75,7 +74,7 @@ func CompareInfo(l, r *base.Info) *InfoChanges {
}) })
// Version // Version
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Version.ValueNode, LeftNode: l.Version.ValueNode,
RightNode: r.Version.ValueNode, RightNode: r.Version.ValueNode,
Label: v3.VersionLabel, Label: v3.VersionLabel,
@@ -86,7 +85,7 @@ func CompareInfo(l, r *base.Info) *InfoChanges {
}) })
// check properties // check properties
core.CheckProperties(props) CheckProperties(props)
i := new(InfoChanges) i := new(InfoChanges)
@@ -95,11 +94,11 @@ func CompareInfo(l, r *base.Info) *InfoChanges {
i.ContactChanges = CompareContact(l.Contact.Value, r.Contact.Value) i.ContactChanges = CompareContact(l.Contact.Value, r.Contact.Value)
} else { } else {
if l.Contact.Value == nil && r.Contact.Value != nil { if l.Contact.Value == nil && r.Contact.Value != nil {
core.CreateChange(&changes, core.ObjectAdded, v3.ContactLabel, CreateChange(&changes, ObjectAdded, v3.ContactLabel,
nil, r.Contact.ValueNode, false, nil, r.Contact.Value) nil, r.Contact.ValueNode, false, nil, r.Contact.Value)
} }
if l.Contact.Value != nil && r.Contact.Value == nil { if l.Contact.Value != nil && r.Contact.Value == nil {
core.CreateChange(&changes, core.ObjectRemoved, v3.ContactLabel, CreateChange(&changes, ObjectRemoved, v3.ContactLabel,
l.Contact.ValueNode, nil, false, l.Contact.Value, nil) l.Contact.ValueNode, nil, false, l.Contact.Value, nil)
} }
} }
@@ -109,11 +108,11 @@ func CompareInfo(l, r *base.Info) *InfoChanges {
i.LicenseChanges = CompareLicense(l.License.Value, r.License.Value) i.LicenseChanges = CompareLicense(l.License.Value, r.License.Value)
} else { } else {
if l.License.Value == nil && r.License.Value != nil { if l.License.Value == nil && r.License.Value != nil {
core.CreateChange(&changes, core.ObjectAdded, v3.LicenseLabel, CreateChange(&changes, ObjectAdded, v3.LicenseLabel,
nil, r.License.ValueNode, false, nil, r.License.Value) nil, r.License.ValueNode, false, nil, r.License.Value)
} }
if l.License.Value != nil && r.License.Value == nil { if l.License.Value != nil && r.License.Value == nil {
core.CreateChange(&changes, core.ObjectRemoved, v3.LicenseLabel, CreateChange(&changes, ObjectRemoved, v3.LicenseLabel,
l.License.ValueNode, nil, false, r.License.Value, nil) l.License.ValueNode, nil, false, r.License.Value, nil)
} }
} }

View File

@@ -7,7 +7,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -49,7 +48,7 @@ license:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.DescriptionLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.DescriptionLabel, extChanges.Changes[0].Property)
} }
@@ -89,7 +88,7 @@ license:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.TitleLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.TitleLabel, extChanges.Changes[0].Property)
} }
@@ -128,7 +127,7 @@ license:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.VersionLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.VersionLabel, extChanges.Changes[0].Property)
} }
@@ -165,7 +164,7 @@ contact:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.LicenseLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.LicenseLabel, extChanges.Changes[0].Property)
} }
@@ -202,7 +201,7 @@ license:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.LicenseLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.LicenseLabel, extChanges.Changes[0].Property)
} }
@@ -241,7 +240,7 @@ license:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.LicenseChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.LicenseChanges.Changes[0].ChangeType)
assert.Equal(t, v3.NameLabel, extChanges.LicenseChanges.Changes[0].Property) assert.Equal(t, v3.NameLabel, extChanges.LicenseChanges.Changes[0].Property)
} }
@@ -277,7 +276,7 @@ license:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.ContactLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.ContactLabel, extChanges.Changes[0].Property)
} }
@@ -313,7 +312,7 @@ license:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.ContactLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.ContactLabel, extChanges.Changes[0].Property)
} }
@@ -352,7 +351,7 @@ license:
// compare. // compare.
extChanges := CompareInfo(&lDoc, &rDoc) extChanges := CompareInfo(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.ContactChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.ContactChanges.Changes[0].ChangeType)
assert.Equal(t, v3.NameLabel, extChanges.ContactChanges.Changes[0].Property) assert.Equal(t, v3.NameLabel, extChanges.ContactChanges.Changes[0].Property)
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
} }

View File

@@ -6,11 +6,10 @@ package model
import ( import (
v2 "github.com/pb33f/libopenapi/datamodel/low/v2" v2 "github.com/pb33f/libopenapi/datamodel/low/v2"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
type ItemsChanges struct { type ItemsChanges struct {
core.PropertyChanges PropertyChanges
ItemsChanges *ItemsChanges ItemsChanges *ItemsChanges
} }
@@ -32,14 +31,14 @@ func (i *ItemsChanges) TotalBreakingChanges() int {
func CompareItems(l, r *v2.Items) *ItemsChanges { func CompareItems(l, r *v2.Items) *ItemsChanges {
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
ic := new(ItemsChanges) ic := new(ItemsChanges)
// header is identical to items, except for a description. // header is identical to items, except for a description.
props = append(props, addSwaggerHeaderProperties(l, r, &changes)...) props = append(props, addSwaggerHeaderProperties(l, r, &changes)...)
core.CheckProperties(props) CheckProperties(props)
if !l.Items.IsEmpty() && !r.Items.IsEmpty() { if !l.Items.IsEmpty() && !r.Items.IsEmpty() {
// inline, check hashes, if they don't match, compare. // inline, check hashes, if they don't match, compare.
@@ -51,12 +50,12 @@ func CompareItems(l, r *v2.Items) *ItemsChanges {
} }
if l.Items.IsEmpty() && !r.Items.IsEmpty() { if l.Items.IsEmpty() && !r.Items.IsEmpty() {
// added items // added items
core.CreateChange(&changes, core.PropertyAdded, v3.ItemsLabel, CreateChange(&changes, PropertyAdded, v3.ItemsLabel,
nil, r.Items.GetValueNode(), true, nil, r.Items.GetValue()) nil, r.Items.GetValueNode(), true, nil, r.Items.GetValue())
} }
if !l.Items.IsEmpty() && r.Items.IsEmpty() { if !l.Items.IsEmpty() && r.Items.IsEmpty() {
// removed items // removed items
core.CreateChange(&changes, core.PropertyRemoved, v3.ItemsLabel, CreateChange(&changes, PropertyRemoved, v3.ItemsLabel,
l.Items.GetValueNode(), nil, true, l.Items.GetValue(), l.Items.GetValueNode(), nil, true, l.Items.GetValue(),
nil) nil)
} }

View File

@@ -7,7 +7,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v2"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -96,7 +95,7 @@ items:
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.ItemsLabel, changes.Changes[0].Property) assert.Equal(t, v3.ItemsLabel, changes.Changes[0].Property)
assert.Equal(t, core.PropertyAdded, changes.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, changes.Changes[0].ChangeType)
} }
func TestCompareItems_RemoveItems(t *testing.T) { func TestCompareItems_RemoveItems(t *testing.T) {
@@ -125,7 +124,7 @@ items:
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.ItemsLabel, changes.Changes[0].Property) assert.Equal(t, v3.ItemsLabel, changes.Changes[0].Property)
assert.Equal(t, core.PropertyRemoved, changes.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, changes.Changes[0].ChangeType)
} }
func TestCompareItems_RefVsInlineIdentical(t *testing.T) { func TestCompareItems_RefVsInlineIdentical(t *testing.T) {

View File

@@ -6,12 +6,11 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
// LicenseChanges represent changes to a License object that is a child of Info object. Part of an OpenAPI document // LicenseChanges represent changes to a License object that is a child of Info object. Part of an OpenAPI document
type LicenseChanges struct { type LicenseChanges struct {
core.PropertyChanges PropertyChanges
} }
// TotalChanges represents the total number of changes made to a License instance. // TotalChanges represents the total number of changes made to a License instance.
@@ -29,11 +28,11 @@ func (l *LicenseChanges) TotalBreakingChanges() int {
// returns nil. // returns nil.
func CompareLicense(l, r *base.License) *LicenseChanges { func CompareLicense(l, r *base.License) *LicenseChanges {
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
// check URL // check URL
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.URL.ValueNode, LeftNode: l.URL.ValueNode,
RightNode: r.URL.ValueNode, RightNode: r.URL.ValueNode,
Label: v3.URLLabel, Label: v3.URLLabel,
@@ -44,7 +43,7 @@ func CompareLicense(l, r *base.License) *LicenseChanges {
}) })
// check name // check name
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Name.ValueNode, LeftNode: l.Name.ValueNode,
RightNode: r.Name.ValueNode, RightNode: r.Name.ValueNode,
Label: v3.NameLabel, Label: v3.NameLabel,
@@ -55,7 +54,7 @@ func CompareLicense(l, r *base.License) *LicenseChanges {
}) })
// check everything. // check everything.
core.CheckProperties(props) CheckProperties(props)
lc := new(LicenseChanges) lc := new(LicenseChanges)
lc.Changes = changes lc.Changes = changes

View File

@@ -6,7 +6,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base" lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -34,7 +33,7 @@ url: https://pb33f.io`
// compare. // compare.
extChanges := CompareLicense(&lDoc, &rDoc) extChanges := CompareLicense(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
} }
@@ -61,7 +60,7 @@ url: https://pb33f.io`
// compare. // compare.
extChanges := CompareLicense(&lDoc, &rDoc) extChanges := CompareLicense(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }
@@ -87,7 +86,7 @@ name: buckaroo`
// compare. // compare.
extChanges := CompareLicense(&lDoc, &rDoc) extChanges := CompareLicense(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
@@ -113,7 +112,7 @@ name: buckaroo`
// compare. // compare.
extChanges := CompareLicense(&lDoc, &rDoc) extChanges := CompareLicense(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
@@ -138,7 +137,7 @@ func TestCompareLicense_URLModified(t *testing.T) {
// compare. // compare.
extChanges := CompareLicense(&lDoc, &rDoc) extChanges := CompareLicense(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
} }
@@ -164,8 +163,8 @@ url: https://pb33f.io`
// compare. // compare.
extChanges := CompareLicense(&lDoc, &rDoc) extChanges := CompareLicense(&lDoc, &rDoc)
assert.Equal(t, 2, extChanges.TotalChanges()) assert.Equal(t, 2, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[1].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[1].ChangeType)
} }
func TestCompareLicense_Identical(t *testing.T) { func TestCompareLicense_Identical(t *testing.T) {

View File

@@ -5,11 +5,10 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
type MediaTypeChanges struct { type MediaTypeChanges struct {
core.PropertyChanges PropertyChanges
SchemaChanges *SchemaChanges SchemaChanges *SchemaChanges
ExtensionChanges *ExtensionChanges ExtensionChanges *ExtensionChanges
ExampleChanges map[string]*ExampleChanges ExampleChanges map[string]*ExampleChanges
@@ -53,8 +52,8 @@ func (m *MediaTypeChanges) TotalBreakingChanges() int {
func CompareMediaTypes(l, r *v3.MediaType) *MediaTypeChanges { func CompareMediaTypes(l, r *v3.MediaType) *MediaTypeChanges {
var props []*core.PropertyCheck var props []*PropertyCheck
var changes []*core.Change var changes []*Change
mc := new(MediaTypeChanges) mc := new(MediaTypeChanges)
@@ -62,27 +61,27 @@ func CompareMediaTypes(l, r *v3.MediaType) *MediaTypeChanges {
addPropertyCheck(&props, l.Example.ValueNode, r.Example.ValueNode, addPropertyCheck(&props, l.Example.ValueNode, r.Example.ValueNode,
l.Example.Value, r.Example.Value, &changes, v3.ExampleLabel, false) l.Example.Value, r.Example.Value, &changes, v3.ExampleLabel, false)
core.CheckProperties(props) CheckProperties(props)
// schema // schema
if !l.Schema.IsEmpty() && !r.Schema.IsEmpty() { if !l.Schema.IsEmpty() && !r.Schema.IsEmpty() {
mc.SchemaChanges = CompareSchemas(l.Schema.Value, r.Schema.Value) mc.SchemaChanges = CompareSchemas(l.Schema.Value, r.Schema.Value)
} }
if !l.Schema.IsEmpty() && r.Schema.IsEmpty() { if !l.Schema.IsEmpty() && r.Schema.IsEmpty() {
core.CreateChange(&changes, core.ObjectRemoved, v3.SchemaLabel, l.Schema.ValueNode, CreateChange(&changes, ObjectRemoved, v3.SchemaLabel, l.Schema.ValueNode,
nil, true, l.Schema.Value, nil) nil, true, l.Schema.Value, nil)
} }
if l.Schema.IsEmpty() && !r.Schema.IsEmpty() { if l.Schema.IsEmpty() && !r.Schema.IsEmpty() {
core.CreateChange(&changes, core.ObjectAdded, v3.SchemaLabel, nil, CreateChange(&changes, ObjectAdded, v3.SchemaLabel, nil,
r.Schema.ValueNode, true, nil, r.Schema.Value) r.Schema.ValueNode, true, nil, r.Schema.Value)
} }
// examples // examples
mc.ExampleChanges = core.CheckMapForChanges(l.Examples.Value, r.Examples.Value, mc.ExampleChanges = CheckMapForChanges(l.Examples.Value, r.Examples.Value,
&changes, v3.ExamplesLabel, CompareExamples) &changes, v3.ExamplesLabel, CompareExamples)
// encoding // encoding
mc.EncodingChanges = core.CheckMapForChanges(l.Encoding.Value, r.Encoding.Value, mc.EncodingChanges = CheckMapForChanges(l.Encoding.Value, r.Encoding.Value,
&changes, v3.EncodingLabel, CompareEncoding) &changes, v3.EncodingLabel, CompareEncoding)
mc.ExtensionChanges = CompareExtensions(l.Extensions, r.Extensions) mc.ExtensionChanges = CompareExtensions(l.Extensions, r.Extensions)

View File

@@ -6,7 +6,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -86,7 +85,7 @@ encoding:
assert.NotNil(t, extChanges) assert.NotNil(t, extChanges)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.ExampleLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.ExampleLabel, extChanges.Changes[0].Property)
} }
@@ -125,7 +124,7 @@ encoding:
assert.NotNil(t, extChanges) assert.NotNil(t, extChanges)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.SchemaLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.SchemaLabel, extChanges.Changes[0].Property)
} }
@@ -164,7 +163,7 @@ encoding:
assert.NotNil(t, extChanges) assert.NotNil(t, extChanges)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, v3.SchemaLabel, extChanges.Changes[0].Property) assert.Equal(t, v3.SchemaLabel, extChanges.Changes[0].Property)
} }

View File

@@ -8,13 +8,12 @@ import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
v2 "github.com/pb33f/libopenapi/datamodel/low/v2" v2 "github.com/pb33f/libopenapi/datamodel/low/v2"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"reflect" "reflect"
) )
type ParameterChanges struct { type ParameterChanges struct {
core.PropertyChanges PropertyChanges
SchemaChanges *SchemaChanges SchemaChanges *SchemaChanges
ExtensionChanges *ExtensionChanges ExtensionChanges *ExtensionChanges
@@ -62,9 +61,9 @@ func (p *ParameterChanges) TotalBreakingChanges() int {
return c return c
} }
func addPropertyCheck(props *[]*core.PropertyCheck, func addPropertyCheck(props *[]*PropertyCheck,
lvn, rvn *yaml.Node, lv, rv any, changes *[]*core.Change, label string, breaking bool) { lvn, rvn *yaml.Node, lv, rv any, changes *[]*Change, label string, breaking bool) {
*props = append(*props, &core.PropertyCheck{ *props = append(*props, &PropertyCheck{
LeftNode: lvn, LeftNode: lvn,
RightNode: rvn, RightNode: rvn,
Label: label, Label: label,
@@ -75,8 +74,8 @@ func addPropertyCheck(props *[]*core.PropertyCheck,
}) })
} }
func addOpenAPIParameterProperties(left, right low.IsParameter, changes *[]*core.Change) []*core.PropertyCheck { func addOpenAPIParameterProperties(left, right low.IsParameter, changes *[]*Change) []*PropertyCheck {
var props []*core.PropertyCheck var props []*PropertyCheck
// style // style
addPropertyCheck(&props, left.GetStyle().ValueNode, right.GetStyle().ValueNode, addPropertyCheck(&props, left.GetStyle().ValueNode, right.GetStyle().ValueNode,
@@ -101,8 +100,8 @@ func addOpenAPIParameterProperties(left, right low.IsParameter, changes *[]*core
return props return props
} }
func addSwaggerParameterProperties(left, right low.IsParameter, changes *[]*core.Change) []*core.PropertyCheck { func addSwaggerParameterProperties(left, right low.IsParameter, changes *[]*Change) []*PropertyCheck {
var props []*core.PropertyCheck var props []*PropertyCheck
// type // type
addPropertyCheck(&props, left.GetType().ValueNode, right.GetType().ValueNode, addPropertyCheck(&props, left.GetType().ValueNode, right.GetType().ValueNode,
@@ -167,8 +166,8 @@ func addSwaggerParameterProperties(left, right low.IsParameter, changes *[]*core
return props return props
} }
func addCommonParameterProperties(left, right low.IsParameter, changes *[]*core.Change) []*core.PropertyCheck { func addCommonParameterProperties(left, right low.IsParameter, changes *[]*Change) []*PropertyCheck {
var props []*core.PropertyCheck var props []*PropertyCheck
addPropertyCheck(&props, left.GetName().ValueNode, right.GetName().ValueNode, addPropertyCheck(&props, left.GetName().ValueNode, right.GetName().ValueNode,
left.GetName(), right.GetName(), changes, v3.NameLabel, true) left.GetName(), right.GetName(), changes, v3.NameLabel, true)
@@ -194,8 +193,8 @@ func addCommonParameterProperties(left, right low.IsParameter, changes *[]*core.
func CompareParameters(l, r any) *ParameterChanges { func CompareParameters(l, r any) *ParameterChanges {
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
pc := new(ParameterChanges) pc := new(ParameterChanges)
var lSchema *base.SchemaProxy var lSchema *base.SchemaProxy
@@ -231,19 +230,19 @@ func CompareParameters(l, r any) *ParameterChanges {
} }
} }
if lParam.Items.IsEmpty() && !rParam.Items.IsEmpty() { if lParam.Items.IsEmpty() && !rParam.Items.IsEmpty() {
core.CreateChange(&changes, core.ObjectAdded, v3.ItemsLabel, CreateChange(&changes, ObjectAdded, v3.ItemsLabel,
nil, rParam.Items.ValueNode, true, nil, nil, rParam.Items.ValueNode, true, nil,
rParam.Items.Value) rParam.Items.Value)
} }
if !lParam.Items.IsEmpty() && rParam.Items.IsEmpty() { if !lParam.Items.IsEmpty() && rParam.Items.IsEmpty() {
core.CreateChange(&changes, core.ObjectRemoved, v3.ItemsLabel, CreateChange(&changes, ObjectRemoved, v3.ItemsLabel,
lParam.Items.ValueNode, nil, true, lParam.Items.Value, lParam.Items.ValueNode, nil, true, lParam.Items.Value,
nil) nil)
} }
// enum // enum
if len(lParam.Enum.Value) > 0 || len(rParam.Enum.Value) > 0 { if len(lParam.Enum.Value) > 0 || len(rParam.Enum.Value) > 0 {
core.ExtractStringValueSliceChanges(lParam.Enum.Value, rParam.Enum.Value, &changes, v3.EnumLabel) ExtractStringValueSliceChanges(lParam.Enum.Value, rParam.Enum.Value, &changes, v3.EnumLabel)
} }
} }
@@ -273,26 +272,26 @@ func CompareParameters(l, r any) *ParameterChanges {
checkParameterExample(lParam.Example, rParam.Example, changes) checkParameterExample(lParam.Example, rParam.Example, changes)
// examples // examples
pc.ExamplesChanges = core.CheckMapForChanges(lParam.Examples.Value, rParam.Examples.Value, pc.ExamplesChanges = CheckMapForChanges(lParam.Examples.Value, rParam.Examples.Value,
&changes, v3.ExamplesLabel, CompareExamples) &changes, v3.ExamplesLabel, CompareExamples)
// content // content
pc.ContentChanges = core.CheckMapForChanges(lParam.Content.Value, rParam.Content.Value, pc.ContentChanges = CheckMapForChanges(lParam.Content.Value, rParam.Content.Value,
&changes, v3.ContentLabel, CompareMediaTypes) &changes, v3.ContentLabel, CompareMediaTypes)
} }
core.CheckProperties(props) CheckProperties(props)
if lSchema != nil && rSchema != nil { if lSchema != nil && rSchema != nil {
pc.SchemaChanges = CompareSchemas(lSchema, rSchema) pc.SchemaChanges = CompareSchemas(lSchema, rSchema)
} }
if lSchema != nil && rSchema == nil { if lSchema != nil && rSchema == nil {
core.CreateChange(&changes, core.ObjectRemoved, v3.SchemaLabel, CreateChange(&changes, ObjectRemoved, v3.SchemaLabel,
lSchema.GetValueNode(), nil, true, lSchema, lSchema.GetValueNode(), nil, true, lSchema,
nil) nil)
} }
if lSchema == nil && rSchema != nil { if lSchema == nil && rSchema != nil {
core.CreateChange(&changes, core.ObjectAdded, v3.SchemaLabel, CreateChange(&changes, ObjectAdded, v3.SchemaLabel,
nil, rSchema.GetValueNode(), true, nil, nil, rSchema.GetValueNode(), true, nil,
rSchema) rSchema)
} }
@@ -305,22 +304,22 @@ func CompareParameters(l, r any) *ParameterChanges {
return pc return pc
} }
func checkParameterExample(expLeft, expRight low.NodeReference[any], changes []*core.Change) { func checkParameterExample(expLeft, expRight low.NodeReference[any], changes []*Change) {
if !expLeft.IsEmpty() && !expRight.IsEmpty() { if !expLeft.IsEmpty() && !expRight.IsEmpty() {
if low.GenerateHashString(expLeft.GetValue()) != low.GenerateHashString(expRight.GetValue()) { if low.GenerateHashString(expLeft.GetValue()) != low.GenerateHashString(expRight.GetValue()) {
core.CreateChange(&changes, core.Modified, v3.ExampleLabel, CreateChange(&changes, Modified, v3.ExampleLabel,
expLeft.GetValueNode(), expRight.GetValueNode(), false, expLeft.GetValueNode(), expRight.GetValueNode(), false,
expLeft.GetValue(), expRight.GetValue()) expLeft.GetValue(), expRight.GetValue())
} }
} }
if expLeft.Value == nil && expRight.Value != nil { if expLeft.Value == nil && expRight.Value != nil {
core.CreateChange(&changes, core.PropertyAdded, v3.ExampleLabel, CreateChange(&changes, PropertyAdded, v3.ExampleLabel,
nil, expRight.GetValueNode(), false, nil, expRight.GetValueNode(), false,
nil, expRight.GetValue()) nil, expRight.GetValue())
} }
if expLeft.Value != nil && expRight.Value == nil { if expLeft.Value != nil && expRight.Value == nil {
core.CreateChange(&changes, core.PropertyRemoved, v3.ExampleLabel, CreateChange(&changes, PropertyRemoved, v3.ExampleLabel,
expLeft.GetValueNode(), nil, false, expLeft.GetValueNode(), nil, false,
expLeft.GetValue(), nil) expLeft.GetValue(), nil)

View File

@@ -7,7 +7,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v2"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -107,7 +106,7 @@ schema:
extChanges := CompareParameters(&lDoc, &rDoc) extChanges := CompareParameters(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
} }
@@ -134,7 +133,7 @@ schema:
extChanges := CompareParameters(&rDoc, &lDoc) extChanges := CompareParameters(&rDoc, &lDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
} }
@@ -231,7 +230,7 @@ example: a string`
extChanges := CompareParameters(&lDoc, &rDoc) extChanges := CompareParameters(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.PropertyAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareParameters_V3_ExampleRemove(t *testing.T) { func TestCompareParameters_V3_ExampleRemove(t *testing.T) {
@@ -256,7 +255,7 @@ example: a string`
extChanges := CompareParameters(&rDoc, &lDoc) extChanges := CompareParameters(&rDoc, &lDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareParameters_V3_ExamplesChanged(t *testing.T) { func TestCompareParameters_V3_ExamplesChanged(t *testing.T) {
@@ -284,7 +283,7 @@ func TestCompareParameters_V3_ExamplesChanged(t *testing.T) {
extChanges := CompareParameters(&lDoc, &rDoc) extChanges := CompareParameters(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.Modified, extChanges.ExamplesChanges["anExample"].Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.ExamplesChanges["anExample"].Changes[0].ChangeType)
} }
func TestCompareParameters_V3_ExamplesAdded(t *testing.T) { func TestCompareParameters_V3_ExamplesAdded(t *testing.T) {
@@ -315,7 +314,7 @@ func TestCompareParameters_V3_ExamplesAdded(t *testing.T) {
extChanges := CompareParameters(&lDoc, &rDoc) extChanges := CompareParameters(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareParameters_V3_ExamplesRemoved(t *testing.T) { func TestCompareParameters_V3_ExamplesRemoved(t *testing.T) {
@@ -346,7 +345,7 @@ func TestCompareParameters_V3_ExamplesRemoved(t *testing.T) {
extChanges := CompareParameters(&rDoc, &lDoc) extChanges := CompareParameters(&rDoc, &lDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareParameters_V3_ContentChanged(t *testing.T) { func TestCompareParameters_V3_ContentChanged(t *testing.T) {
@@ -377,7 +376,7 @@ func TestCompareParameters_V3_ContentChanged(t *testing.T) {
extChanges := CompareParameters(&lDoc, &rDoc) extChanges := CompareParameters(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.Modified, assert.Equal(t, Modified,
extChanges.ContentChanges["application/json"].SchemaChanges.Changes[0].ChangeType) extChanges.ContentChanges["application/json"].SchemaChanges.Changes[0].ChangeType)
} }
@@ -412,7 +411,7 @@ func TestCompareParameters_V3_ContentAdded(t *testing.T) {
extChanges := CompareParameters(&lDoc, &rDoc) extChanges := CompareParameters(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareParameters_V2_DefaultChange(t *testing.T) { func TestCompareParameters_V2_DefaultChange(t *testing.T) {
@@ -511,7 +510,7 @@ example: a string`
extChanges := CompareParameters(&rDoc, &lDoc) extChanges := CompareParameters(&rDoc, &lDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareParameters_V2_Equal(t *testing.T) { func TestCompareParameters_V2_Equal(t *testing.T) {
@@ -581,7 +580,7 @@ func TestCompareParameters_V2_ItemsChange(t *testing.T) {
extChanges := CompareParameters(&lDoc, &rDoc) extChanges := CompareParameters(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.Modified, extChanges.ItemsChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.ItemsChanges.Changes[0].ChangeType)
} }
@@ -608,7 +607,7 @@ items:
extChanges := CompareParameters(&lDoc, &rDoc) extChanges := CompareParameters(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareParameters_V2_ItemsRemove(t *testing.T) { func TestCompareParameters_V2_ItemsRemove(t *testing.T) {
@@ -634,7 +633,7 @@ items:
extChanges := CompareParameters(&rDoc, &lDoc) extChanges := CompareParameters(&rDoc, &lDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
} }
func TestCompareParameters_V2_Extensions(t *testing.T) { func TestCompareParameters_V2_Extensions(t *testing.T) {

View File

@@ -8,7 +8,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"sort" "sort"
"sync" "sync"
@@ -21,7 +20,7 @@ import (
// changes, and not the child for example, adding a new schema to `anyOf` will create a new change result in // changes, and not the child for example, adding a new schema to `anyOf` will create a new change result in
// PropertyChanges.Changes, and not in the AnyOfChanges property. // PropertyChanges.Changes, and not in the AnyOfChanges property.
type SchemaChanges struct { type SchemaChanges struct {
core.PropertyChanges PropertyChanges
DiscriminatorChanges *DiscriminatorChanges DiscriminatorChanges *DiscriminatorChanges
AllOfChanges []*SchemaChanges AllOfChanges []*SchemaChanges
AnyOfChanges []*SchemaChanges AnyOfChanges []*SchemaChanges
@@ -131,18 +130,18 @@ func (s *SchemaChanges) TotalBreakingChanges() int {
func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges { func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges {
sc := new(SchemaChanges) sc := new(SchemaChanges)
var changes []*core.Change var changes []*Change
// Added // Added
if l == nil && r != nil { if l == nil && r != nil {
core.CreateChange(&changes, core.ObjectAdded, v3.SchemaLabel, CreateChange(&changes, ObjectAdded, v3.SchemaLabel,
nil, nil, true, nil, r) nil, nil, true, nil, r)
sc.Changes = changes sc.Changes = changes
} }
// Removed // Removed
if l != nil && r == nil { if l != nil && r == nil {
core.CreateChange(&changes, core.ObjectRemoved, v3.SchemaLabel, CreateChange(&changes, ObjectRemoved, v3.SchemaLabel,
nil, nil, true, l, nil) nil, nil, true, l, nil)
sc.Changes = changes sc.Changes = changes
} }
@@ -157,7 +156,7 @@ func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges {
return nil return nil
} else { } else {
// references are different, that's all we care to know. // references are different, that's all we care to know.
core.CreateChange(&changes, core.Modified, v3.RefLabel, CreateChange(&changes, Modified, v3.RefLabel,
l.GetValueNode().Content[1], r.GetValueNode().Content[1], true, l.GetSchemaReference(), l.GetValueNode().Content[1], r.GetValueNode().Content[1], true, l.GetSchemaReference(),
r.GetSchemaReference()) r.GetSchemaReference())
sc.Changes = changes sc.Changes = changes
@@ -167,7 +166,7 @@ func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges {
// changed from inline to ref // changed from inline to ref
if !l.IsSchemaReference() && r.IsSchemaReference() { if !l.IsSchemaReference() && r.IsSchemaReference() {
core.CreateChange(&changes, core.Modified, v3.RefLabel, CreateChange(&changes, Modified, v3.RefLabel,
l.GetValueNode(), r.GetValueNode().Content[1], true, l, r.GetSchemaReference()) l.GetValueNode(), r.GetValueNode().Content[1], true, l, r.GetSchemaReference())
sc.Changes = changes sc.Changes = changes
return sc // we're done here return sc // we're done here
@@ -175,7 +174,7 @@ func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges {
// changed from ref to inline // changed from ref to inline
if l.IsSchemaReference() && !r.IsSchemaReference() { if l.IsSchemaReference() && !r.IsSchemaReference() {
core.CreateChange(&changes, core.Modified, v3.RefLabel, CreateChange(&changes, Modified, v3.RefLabel,
l.GetValueNode().Content[1], r.GetValueNode(), true, l.GetSchemaReference(), r) l.GetValueNode().Content[1], r.GetValueNode(), true, l.GetSchemaReference(), r)
sc.Changes = changes sc.Changes = changes
return sc // done, nothing else to do. return sc // done, nothing else to do.
@@ -235,15 +234,15 @@ func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges {
return sc return sc
} }
func checkSchemaXML(lSchema *base.Schema, rSchema *base.Schema, changes *[]*core.Change, sc *SchemaChanges) { func checkSchemaXML(lSchema *base.Schema, rSchema *base.Schema, changes *[]*Change, sc *SchemaChanges) {
// XML removed // XML removed
if lSchema.XML.Value != nil && rSchema.XML.Value == nil { if lSchema.XML.Value != nil && rSchema.XML.Value == nil {
core.CreateChange(changes, core.ObjectRemoved, v3.XMLLabel, CreateChange(changes, ObjectRemoved, v3.XMLLabel,
lSchema.XML.GetValueNode(), nil, true, lSchema.XML.GetValue(), nil) lSchema.XML.GetValueNode(), nil, true, lSchema.XML.GetValue(), nil)
} }
// XML added // XML added
if lSchema.XML.Value == nil && rSchema.XML.Value != nil { if lSchema.XML.Value == nil && rSchema.XML.Value != nil {
core.CreateChange(changes, core.ObjectAdded, v3.XMLLabel, CreateChange(changes, ObjectAdded, v3.XMLLabel,
nil, rSchema.XML.GetValueNode(), false, nil, rSchema.XML.GetValue()) nil, rSchema.XML.GetValueNode(), false, nil, rSchema.XML.GetValue())
} }
@@ -258,7 +257,7 @@ func checkSchemaXML(lSchema *base.Schema, rSchema *base.Schema, changes *[]*core
func checkPropertiesPropertyOfASchema( func checkPropertiesPropertyOfASchema(
lSchema *base.Schema, lSchema *base.Schema,
rSchema *base.Schema, rSchema *base.Schema,
changes *[]*core.Change, changes *[]*Change,
sc *SchemaChanges, sc *SchemaChanges,
doneChan chan bool) int { doneChan chan bool) int {
@@ -319,10 +318,10 @@ func checkPropertiesPropertyOfASchema(
if lProps[w] != rProps[w] { if lProps[w] != rProps[w] {
// old removed, new added. // old removed, new added.
core.CreateChange(changes, core.ObjectAdded, v3.PropertiesLabel, CreateChange(changes, ObjectAdded, v3.PropertiesLabel,
nil, rKeyNodes[rProps[w]], false, nil, rEntities[rProps[w]]) nil, rKeyNodes[rProps[w]], false, nil, rEntities[rProps[w]])
core.CreateChange(changes, core.ObjectRemoved, v3.PropertiesLabel, CreateChange(changes, ObjectRemoved, v3.PropertiesLabel,
lKeyNodes[lProps[w]], nil, true, lEntities[lProps[w]], nil) lKeyNodes[lProps[w]], nil, true, lEntities[lProps[w]], nil)
} }
@@ -337,7 +336,7 @@ func checkPropertiesPropertyOfASchema(
go checkProperty(lProps[w], lEntities[lProps[w]], rEntities[rProps[w]], propChanges, doneChan) go checkProperty(lProps[w], lEntities[lProps[w]], rEntities[rProps[w]], propChanges, doneChan)
} }
if w >= len(rProps) { if w >= len(rProps) {
core.CreateChange(changes, core.ObjectRemoved, v3.PropertiesLabel, CreateChange(changes, ObjectRemoved, v3.PropertiesLabel,
lKeyNodes[lProps[w]], nil, true, lEntities[lProps[w]], nil) lKeyNodes[lProps[w]], nil, true, lEntities[lProps[w]], nil)
} }
} }
@@ -351,7 +350,7 @@ func checkPropertiesPropertyOfASchema(
go checkProperty(rProps[w], lEntities[lProps[w]], rEntities[rProps[w]], propChanges, doneChan) go checkProperty(rProps[w], lEntities[lProps[w]], rEntities[rProps[w]], propChanges, doneChan)
} }
if w >= len(lProps) { if w >= len(lProps) {
core.CreateChange(changes, core.ObjectAdded, v3.PropertiesLabel, CreateChange(changes, ObjectAdded, v3.PropertiesLabel,
nil, rKeyNodes[rProps[w]], false, nil, rEntities[rProps[w]]) nil, rKeyNodes[rProps[w]], false, nil, rEntities[rProps[w]])
} }
} }
@@ -363,12 +362,12 @@ func checkPropertiesPropertyOfASchema(
func checkSchemaPropertyChanges( func checkSchemaPropertyChanges(
lSchema *base.Schema, lSchema *base.Schema,
rSchema *base.Schema, rSchema *base.Schema,
changes *[]*core.Change, sc *SchemaChanges) { changes *[]*Change, sc *SchemaChanges) {
var props []*core.PropertyCheck var props []*PropertyCheck
// $schema (breaking change) // $schema (breaking change)
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.SchemaTypeRef.ValueNode, LeftNode: lSchema.SchemaTypeRef.ValueNode,
RightNode: rSchema.SchemaTypeRef.ValueNode, RightNode: rSchema.SchemaTypeRef.ValueNode,
Label: v3.SchemaDialectLabel, Label: v3.SchemaDialectLabel,
@@ -379,7 +378,7 @@ func checkSchemaPropertyChanges(
}) })
// ExclusiveMaximum // ExclusiveMaximum
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.ExclusiveMaximum.ValueNode, LeftNode: lSchema.ExclusiveMaximum.ValueNode,
RightNode: rSchema.ExclusiveMaximum.ValueNode, RightNode: rSchema.ExclusiveMaximum.ValueNode,
Label: v3.ExclusiveMaximumLabel, Label: v3.ExclusiveMaximumLabel,
@@ -390,7 +389,7 @@ func checkSchemaPropertyChanges(
}) })
// ExclusiveMinimum // ExclusiveMinimum
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.ExclusiveMinimum.ValueNode, LeftNode: lSchema.ExclusiveMinimum.ValueNode,
RightNode: rSchema.ExclusiveMinimum.ValueNode, RightNode: rSchema.ExclusiveMinimum.ValueNode,
Label: v3.ExclusiveMinimumLabel, Label: v3.ExclusiveMinimumLabel,
@@ -401,7 +400,7 @@ func checkSchemaPropertyChanges(
}) })
// Type // Type
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Type.ValueNode, LeftNode: lSchema.Type.ValueNode,
RightNode: rSchema.Type.ValueNode, RightNode: rSchema.Type.ValueNode,
Label: v3.TypeLabel, Label: v3.TypeLabel,
@@ -412,7 +411,7 @@ func checkSchemaPropertyChanges(
}) })
// Title // Title
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Title.ValueNode, LeftNode: lSchema.Title.ValueNode,
RightNode: rSchema.Title.ValueNode, RightNode: rSchema.Title.ValueNode,
Label: v3.TitleLabel, Label: v3.TitleLabel,
@@ -423,7 +422,7 @@ func checkSchemaPropertyChanges(
}) })
// MultipleOf // MultipleOf
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.MultipleOf.ValueNode, LeftNode: lSchema.MultipleOf.ValueNode,
RightNode: rSchema.MultipleOf.ValueNode, RightNode: rSchema.MultipleOf.ValueNode,
Label: v3.MultipleOfLabel, Label: v3.MultipleOfLabel,
@@ -434,7 +433,7 @@ func checkSchemaPropertyChanges(
}) })
// Maximum // Maximum
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Maximum.ValueNode, LeftNode: lSchema.Maximum.ValueNode,
RightNode: rSchema.Maximum.ValueNode, RightNode: rSchema.Maximum.ValueNode,
Label: v3.MaximumLabel, Label: v3.MaximumLabel,
@@ -445,7 +444,7 @@ func checkSchemaPropertyChanges(
}) })
// Minimum // Minimum
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Minimum.ValueNode, LeftNode: lSchema.Minimum.ValueNode,
RightNode: rSchema.Minimum.ValueNode, RightNode: rSchema.Minimum.ValueNode,
Label: v3.MinimumLabel, Label: v3.MinimumLabel,
@@ -456,7 +455,7 @@ func checkSchemaPropertyChanges(
}) })
// MaxLength // MaxLength
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.MaxLength.ValueNode, LeftNode: lSchema.MaxLength.ValueNode,
RightNode: rSchema.MaxLength.ValueNode, RightNode: rSchema.MaxLength.ValueNode,
Label: v3.MaxLengthLabel, Label: v3.MaxLengthLabel,
@@ -467,7 +466,7 @@ func checkSchemaPropertyChanges(
}) })
// MinLength // MinLength
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.MinLength.ValueNode, LeftNode: lSchema.MinLength.ValueNode,
RightNode: rSchema.MinLength.ValueNode, RightNode: rSchema.MinLength.ValueNode,
Label: v3.MinLengthLabel, Label: v3.MinLengthLabel,
@@ -478,7 +477,7 @@ func checkSchemaPropertyChanges(
}) })
// Pattern // Pattern
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Pattern.ValueNode, LeftNode: lSchema.Pattern.ValueNode,
RightNode: rSchema.Pattern.ValueNode, RightNode: rSchema.Pattern.ValueNode,
Label: v3.PatternLabel, Label: v3.PatternLabel,
@@ -489,7 +488,7 @@ func checkSchemaPropertyChanges(
}) })
// Format // Format
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Format.ValueNode, LeftNode: lSchema.Format.ValueNode,
RightNode: rSchema.Format.ValueNode, RightNode: rSchema.Format.ValueNode,
Label: v3.FormatLabel, Label: v3.FormatLabel,
@@ -500,7 +499,7 @@ func checkSchemaPropertyChanges(
}) })
// MaxItems // MaxItems
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.MaxItems.ValueNode, LeftNode: lSchema.MaxItems.ValueNode,
RightNode: rSchema.MaxItems.ValueNode, RightNode: rSchema.MaxItems.ValueNode,
Label: v3.MaxItemsLabel, Label: v3.MaxItemsLabel,
@@ -511,7 +510,7 @@ func checkSchemaPropertyChanges(
}) })
// MinItems // MinItems
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.MinItems.ValueNode, LeftNode: lSchema.MinItems.ValueNode,
RightNode: rSchema.MinItems.ValueNode, RightNode: rSchema.MinItems.ValueNode,
Label: v3.MinItemsLabel, Label: v3.MinItemsLabel,
@@ -522,7 +521,7 @@ func checkSchemaPropertyChanges(
}) })
// MaxProperties // MaxProperties
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.MaxProperties.ValueNode, LeftNode: lSchema.MaxProperties.ValueNode,
RightNode: rSchema.MaxProperties.ValueNode, RightNode: rSchema.MaxProperties.ValueNode,
Label: v3.MaxPropertiesLabel, Label: v3.MaxPropertiesLabel,
@@ -533,7 +532,7 @@ func checkSchemaPropertyChanges(
}) })
// MinProperties // MinProperties
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.MinProperties.ValueNode, LeftNode: lSchema.MinProperties.ValueNode,
RightNode: rSchema.MinProperties.ValueNode, RightNode: rSchema.MinProperties.ValueNode,
Label: v3.MinPropertiesLabel, Label: v3.MinPropertiesLabel,
@@ -544,7 +543,7 @@ func checkSchemaPropertyChanges(
}) })
// UniqueItems // UniqueItems
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.UniqueItems.ValueNode, LeftNode: lSchema.UniqueItems.ValueNode,
RightNode: rSchema.UniqueItems.ValueNode, RightNode: rSchema.UniqueItems.ValueNode,
Label: v3.UniqueItemsLabel, Label: v3.UniqueItemsLabel,
@@ -555,7 +554,7 @@ func checkSchemaPropertyChanges(
}) })
// AdditionalProperties // AdditionalProperties
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.AdditionalProperties.ValueNode, LeftNode: lSchema.AdditionalProperties.ValueNode,
RightNode: rSchema.AdditionalProperties.ValueNode, RightNode: rSchema.AdditionalProperties.ValueNode,
Label: v3.AdditionalPropertiesLabel, Label: v3.AdditionalPropertiesLabel,
@@ -566,7 +565,7 @@ func checkSchemaPropertyChanges(
}) })
// Description // Description
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Description.ValueNode, LeftNode: lSchema.Description.ValueNode,
RightNode: rSchema.Description.ValueNode, RightNode: rSchema.Description.ValueNode,
Label: v3.DescriptionLabel, Label: v3.DescriptionLabel,
@@ -577,7 +576,7 @@ func checkSchemaPropertyChanges(
}) })
// ContentEncoding // ContentEncoding
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.ContentEncoding.ValueNode, LeftNode: lSchema.ContentEncoding.ValueNode,
RightNode: rSchema.ContentEncoding.ValueNode, RightNode: rSchema.ContentEncoding.ValueNode,
Label: v3.ContentEncodingLabel, Label: v3.ContentEncodingLabel,
@@ -588,7 +587,7 @@ func checkSchemaPropertyChanges(
}) })
// ContentMediaType // ContentMediaType
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.ContentMediaType.ValueNode, LeftNode: lSchema.ContentMediaType.ValueNode,
RightNode: rSchema.ContentMediaType.ValueNode, RightNode: rSchema.ContentMediaType.ValueNode,
Label: v3.ContentMediaType, Label: v3.ContentMediaType,
@@ -599,7 +598,7 @@ func checkSchemaPropertyChanges(
}) })
// Default // Default
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Default.ValueNode, LeftNode: lSchema.Default.ValueNode,
RightNode: rSchema.Default.ValueNode, RightNode: rSchema.Default.ValueNode,
Label: v3.DefaultLabel, Label: v3.DefaultLabel,
@@ -610,7 +609,7 @@ func checkSchemaPropertyChanges(
}) })
// Nullable // Nullable
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Nullable.ValueNode, LeftNode: lSchema.Nullable.ValueNode,
RightNode: rSchema.Nullable.ValueNode, RightNode: rSchema.Nullable.ValueNode,
Label: v3.NullableLabel, Label: v3.NullableLabel,
@@ -621,7 +620,7 @@ func checkSchemaPropertyChanges(
}) })
// ReadOnly // ReadOnly
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.ReadOnly.ValueNode, LeftNode: lSchema.ReadOnly.ValueNode,
RightNode: rSchema.ReadOnly.ValueNode, RightNode: rSchema.ReadOnly.ValueNode,
Label: v3.ReadOnlyLabel, Label: v3.ReadOnlyLabel,
@@ -632,7 +631,7 @@ func checkSchemaPropertyChanges(
}) })
// WriteOnly // WriteOnly
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.WriteOnly.ValueNode, LeftNode: lSchema.WriteOnly.ValueNode,
RightNode: rSchema.WriteOnly.ValueNode, RightNode: rSchema.WriteOnly.ValueNode,
Label: v3.WriteOnlyLabel, Label: v3.WriteOnlyLabel,
@@ -643,7 +642,7 @@ func checkSchemaPropertyChanges(
}) })
// Example // Example
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Example.ValueNode, LeftNode: lSchema.Example.ValueNode,
RightNode: rSchema.Example.ValueNode, RightNode: rSchema.Example.ValueNode,
Label: v3.ExampleLabel, Label: v3.ExampleLabel,
@@ -654,7 +653,7 @@ func checkSchemaPropertyChanges(
}) })
// Deprecated // Deprecated
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: lSchema.Deprecated.ValueNode, LeftNode: lSchema.Deprecated.ValueNode,
RightNode: rSchema.Deprecated.ValueNode, RightNode: rSchema.Deprecated.ValueNode,
Label: v3.DeprecatedLabel, Label: v3.DeprecatedLabel,
@@ -675,14 +674,14 @@ func checkSchemaPropertyChanges(
} }
for g := range k { for g := range k {
if _, ok := j[g]; !ok { if _, ok := j[g]; !ok {
core.CreateChange(changes, core.PropertyAdded, v3.RequiredLabel, CreateChange(changes, PropertyAdded, v3.RequiredLabel,
nil, rSchema.Required.Value[k[g]].GetValueNode(), true, nil, nil, rSchema.Required.Value[k[g]].GetValueNode(), true, nil,
rSchema.Required.Value[k[g]].GetValue) rSchema.Required.Value[k[g]].GetValue)
} }
} }
for g := range j { for g := range j {
if _, ok := k[g]; !ok { if _, ok := k[g]; !ok {
core.CreateChange(changes, core.PropertyRemoved, v3.RequiredLabel, CreateChange(changes, PropertyRemoved, v3.RequiredLabel,
lSchema.Required.Value[j[g]].GetValueNode(), nil, true, lSchema.Required.Value[j[g]].GetValue, lSchema.Required.Value[j[g]].GetValueNode(), nil, true, lSchema.Required.Value[j[g]].GetValue,
nil) nil)
} }
@@ -699,14 +698,14 @@ func checkSchemaPropertyChanges(
} }
for g := range k { for g := range k {
if _, ok := j[g]; !ok { if _, ok := j[g]; !ok {
core.CreateChange(changes, core.PropertyAdded, v3.EnumLabel, CreateChange(changes, PropertyAdded, v3.EnumLabel,
nil, rSchema.Enum.Value[k[g]].GetValueNode(), false, nil, nil, rSchema.Enum.Value[k[g]].GetValueNode(), false, nil,
rSchema.Enum.Value[k[g]].GetValue) rSchema.Enum.Value[k[g]].GetValue)
} }
} }
for g := range j { for g := range j {
if _, ok := k[g]; !ok { if _, ok := k[g]; !ok {
core.CreateChange(changes, core.PropertyRemoved, v3.EnumLabel, CreateChange(changes, PropertyRemoved, v3.EnumLabel,
lSchema.Enum.Value[j[g]].GetValueNode(), nil, true, lSchema.Enum.Value[j[g]].GetValue, lSchema.Enum.Value[j[g]].GetValueNode(), nil, true, lSchema.Enum.Value[j[g]].GetValue,
nil) nil)
} }
@@ -721,12 +720,12 @@ func checkSchemaPropertyChanges(
} }
// added Discriminator // added Discriminator
if lSchema.Discriminator.Value == nil && rSchema.Discriminator.Value != nil { if lSchema.Discriminator.Value == nil && rSchema.Discriminator.Value != nil {
core.CreateChange(changes, core.ObjectAdded, v3.DiscriminatorLabel, CreateChange(changes, ObjectAdded, v3.DiscriminatorLabel,
nil, rSchema.Discriminator.ValueNode, true, nil, rSchema.Discriminator.Value) nil, rSchema.Discriminator.ValueNode, true, nil, rSchema.Discriminator.Value)
} }
// removed Discriminator // removed Discriminator
if lSchema.Discriminator.Value != nil && rSchema.Discriminator.Value == nil { if lSchema.Discriminator.Value != nil && rSchema.Discriminator.Value == nil {
core.CreateChange(changes, core.ObjectRemoved, v3.DiscriminatorLabel, CreateChange(changes, ObjectRemoved, v3.DiscriminatorLabel,
lSchema.Discriminator.ValueNode, nil, true, lSchema.Discriminator.Value, nil) lSchema.Discriminator.ValueNode, nil, true, lSchema.Discriminator.Value, nil)
} }
@@ -739,12 +738,12 @@ func checkSchemaPropertyChanges(
} }
// added ExternalDocs // added ExternalDocs
if lSchema.ExternalDocs.Value == nil && rSchema.ExternalDocs.Value != nil { if lSchema.ExternalDocs.Value == nil && rSchema.ExternalDocs.Value != nil {
core.CreateChange(changes, core.ObjectAdded, v3.ExternalDocsLabel, CreateChange(changes, ObjectAdded, v3.ExternalDocsLabel,
nil, rSchema.ExternalDocs.ValueNode, false, nil, rSchema.ExternalDocs.Value) nil, rSchema.ExternalDocs.ValueNode, false, nil, rSchema.ExternalDocs.Value)
} }
// removed ExternalDocs // removed ExternalDocs
if lSchema.ExternalDocs.Value != nil && rSchema.ExternalDocs.Value == nil { if lSchema.ExternalDocs.Value != nil && rSchema.ExternalDocs.Value == nil {
core.CreateChange(changes, core.ObjectRemoved, v3.ExternalDocsLabel, CreateChange(changes, ObjectRemoved, v3.ExternalDocsLabel,
lSchema.ExternalDocs.ValueNode, nil, false, lSchema.ExternalDocs.Value, nil) lSchema.ExternalDocs.ValueNode, nil, false, lSchema.ExternalDocs.Value, nil)
} }
@@ -752,10 +751,10 @@ func checkSchemaPropertyChanges(
sc.ExtensionChanges = CompareExtensions(lSchema.Extensions, rSchema.Extensions) sc.ExtensionChanges = CompareExtensions(lSchema.Extensions, rSchema.Extensions)
// check core properties // check core properties
core.CheckProperties(props) CheckProperties(props)
} }
func checkExamples(lSchema *base.Schema, rSchema *base.Schema, changes *[]*core.Change) { func checkExamples(lSchema *base.Schema, rSchema *base.Schema, changes *[]*Change) {
// check examples (3.1+) // check examples (3.1+)
var lExampKey, rExampKey []string var lExampKey, rExampKey []string
lExampN := make(map[string]*yaml.Node) lExampN := make(map[string]*yaml.Node)
@@ -786,7 +785,7 @@ func checkExamples(lSchema *base.Schema, rSchema *base.Schema, changes *[]*core.
if len(lExampKey) == len(rExampKey) { if len(lExampKey) == len(rExampKey) {
for i := range lExampKey { for i := range lExampKey {
if lExampKey[i] != rExampKey[i] { if lExampKey[i] != rExampKey[i] {
core.CreateChange(changes, core.Modified, v3.ExamplesLabel, CreateChange(changes, Modified, v3.ExamplesLabel,
lExampN[lExampKey[i]], rExampN[rExampKey[i]], false, lExampN[lExampKey[i]], rExampN[rExampKey[i]], false,
lExampVal[lExampKey[i]], rExampVal[rExampKey[i]]) lExampVal[lExampKey[i]], rExampVal[rExampKey[i]])
} }
@@ -796,12 +795,12 @@ func checkExamples(lSchema *base.Schema, rSchema *base.Schema, changes *[]*core.
if len(lExampKey) > len(rExampKey) { if len(lExampKey) > len(rExampKey) {
for i := range lExampKey { for i := range lExampKey {
if i < len(rExampKey) && lExampKey[i] != rExampKey[i] { if i < len(rExampKey) && lExampKey[i] != rExampKey[i] {
core.CreateChange(changes, core.Modified, v3.ExamplesLabel, CreateChange(changes, Modified, v3.ExamplesLabel,
lExampN[lExampKey[i]], rExampN[rExampKey[i]], false, lExampN[lExampKey[i]], rExampN[rExampKey[i]], false,
lExampVal[lExampKey[i]], rExampVal[rExampKey[i]]) lExampVal[lExampKey[i]], rExampVal[rExampKey[i]])
} }
if i >= len(rExampKey) { if i >= len(rExampKey) {
core.CreateChange(changes, core.ObjectRemoved, v3.ExamplesLabel, CreateChange(changes, ObjectRemoved, v3.ExamplesLabel,
lExampN[lExampKey[i]], nil, false, lExampN[lExampKey[i]], nil, false,
lExampVal[lExampKey[i]], nil) lExampVal[lExampKey[i]], nil)
} }
@@ -812,12 +811,12 @@ func checkExamples(lSchema *base.Schema, rSchema *base.Schema, changes *[]*core.
if len(lExampKey) < len(rExampKey) { if len(lExampKey) < len(rExampKey) {
for i := range rExampKey { for i := range rExampKey {
if i < len(lExampKey) && lExampKey[i] != rExampKey[i] { if i < len(lExampKey) && lExampKey[i] != rExampKey[i] {
core.CreateChange(changes, core.Modified, v3.ExamplesLabel, CreateChange(changes, Modified, v3.ExamplesLabel,
lExampN[lExampKey[i]], rExampN[rExampKey[i]], false, lExampN[lExampKey[i]], rExampN[rExampKey[i]], false,
lExampVal[lExampKey[i]], rExampVal[rExampKey[i]]) lExampVal[lExampKey[i]], rExampVal[rExampKey[i]])
} }
if i >= len(lExampKey) { if i >= len(lExampKey) {
core.CreateChange(changes, core.ObjectAdded, v3.ExamplesLabel, CreateChange(changes, ObjectAdded, v3.ExamplesLabel,
nil, rExampN[rExampKey[i]], false, nil, rExampN[rExampKey[i]], false,
nil, rExampVal[rExampKey[i]]) nil, rExampVal[rExampKey[i]])
} }
@@ -830,7 +829,7 @@ func extractSchemaChanges(
rSchema []low.ValueReference[*base.SchemaProxy], rSchema []low.ValueReference[*base.SchemaProxy],
label string, label string,
sc *[]*SchemaChanges, sc *[]*SchemaChanges,
changes *[]*core.Change, changes *[]*Change,
done chan bool) { done chan bool) {
// if there is nothing here, there is nothing to do. // if there is nothing here, there is nothing to do.
@@ -885,7 +884,7 @@ func extractSchemaChanges(
*sc = append(*sc, CompareSchemas(lEntities[lKeys[w]], rEntities[rKeys[w]])) *sc = append(*sc, CompareSchemas(lEntities[lKeys[w]], rEntities[rKeys[w]]))
} }
if w >= len(rKeys) { if w >= len(rKeys) {
core.CreateChange(changes, core.ObjectRemoved, label, CreateChange(changes, ObjectRemoved, label,
lEntities[lKeys[w]].GetValueNode(), nil, true, lEntities[lKeys[w]], nil) lEntities[lKeys[w]].GetValueNode(), nil, true, lEntities[lKeys[w]], nil)
} }
} }
@@ -898,7 +897,7 @@ func extractSchemaChanges(
*sc = append(*sc, CompareSchemas(lEntities[lKeys[w]], rEntities[rKeys[w]])) *sc = append(*sc, CompareSchemas(lEntities[lKeys[w]], rEntities[rKeys[w]]))
} }
if w >= len(lKeys) { if w >= len(lKeys) {
core.CreateChange(changes, core.ObjectAdded, label, CreateChange(changes, ObjectAdded, label,
nil, rEntities[rKeys[w]].GetValueNode(), false, nil, rEntities[rKeys[w]]) nil, rEntities[rKeys[w]].GetValueNode(), false, nil, rEntities[rKeys[w]])
} }
} }

View File

@@ -10,7 +10,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
v2 "github.com/pb33f/libopenapi/datamodel/low/v2" v2 "github.com/pb33f/libopenapi/datamodel/low/v2"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing" "testing"
) )
@@ -43,7 +42,7 @@ func TestCompareSchemas_PropertyModification(t *testing.T) {
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, core.Modified, changes.Changes[0].ChangeType) assert.Equal(t, Modified, changes.Changes[0].ChangeType)
assert.Equal(t, "an OK message Changed", changes.Changes[0].New) assert.Equal(t, "an OK message Changed", changes.Changes[0].New)
} }
@@ -68,7 +67,7 @@ func TestCompareSchemas_PropertyAdd(t *testing.T) {
changes := CompareSchemas(lSchemaProxy, rSchemaProxy) changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.PropertyAdded, changes.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "a thing", changes.Changes[0].New) assert.Equal(t, "a thing", changes.Changes[0].New)
assert.Equal(t, v3.DescriptionLabel, changes.Changes[0].Property) assert.Equal(t, v3.DescriptionLabel, changes.Changes[0].Property)
} }
@@ -94,7 +93,7 @@ func TestCompareSchemas_PropertyRemove(t *testing.T) {
changes := CompareSchemas(lSchemaProxy, rSchemaProxy) changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.PropertyRemoved, changes.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "a thing", changes.Changes[0].Original) assert.Equal(t, "a thing", changes.Changes[0].Original)
assert.Equal(t, v3.DescriptionLabel, changes.Changes[0].Property) assert.Equal(t, v3.DescriptionLabel, changes.Changes[0].Property)
} }
@@ -118,7 +117,7 @@ func TestCompareSchemas_Removed(t *testing.T) {
changes := CompareSchemas(lSchemaProxy, rSchemaProxy) changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType)
} }
func TestCompareSchemas_Added(t *testing.T) { func TestCompareSchemas_Added(t *testing.T) {
@@ -140,7 +139,7 @@ func TestCompareSchemas_Added(t *testing.T) {
changes := CompareSchemas(rSchemaProxy, lSchemaProxy) changes := CompareSchemas(rSchemaProxy, lSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
} }
func test_BuildDoc(l, r string) (*v3.Document, *v3.Document) { func test_BuildDoc(l, r string) (*v3.Document, *v3.Document) {
@@ -221,7 +220,7 @@ func TestCompareSchemas_RefChanged(t *testing.T) {
changes := CompareSchemas(lSchemaProxy, rSchemaProxy) changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.Modified, changes.Changes[0].ChangeType) assert.Equal(t, Modified, changes.Changes[0].ChangeType)
assert.Equal(t, "#/components/schemas/Woah", changes.Changes[0].New) assert.Equal(t, "#/components/schemas/Woah", changes.Changes[0].New)
} }
@@ -249,7 +248,7 @@ func TestCompareSchemas_RefToInline(t *testing.T) {
changes := CompareSchemas(lSchemaProxy, rSchemaProxy) changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.Modified, changes.Changes[0].ChangeType) assert.Equal(t, Modified, changes.Changes[0].ChangeType)
assert.Equal(t, v3.RefLabel, changes.Changes[0].Property) assert.Equal(t, v3.RefLabel, changes.Changes[0].Property)
assert.Equal(t, "#/components/schemas/No", changes.Changes[0].Original) assert.Equal(t, "#/components/schemas/No", changes.Changes[0].Original)
@@ -279,7 +278,7 @@ func TestCompareSchemas_InlineToRef(t *testing.T) {
changes := CompareSchemas(rSchemaProxy, lSchemaProxy) changes := CompareSchemas(rSchemaProxy, lSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.Modified, changes.Changes[0].ChangeType) assert.Equal(t, Modified, changes.Changes[0].ChangeType)
assert.Equal(t, v3.RefLabel, changes.Changes[0].Property) assert.Equal(t, v3.RefLabel, changes.Changes[0].Property)
assert.Equal(t, "#/components/schemas/No", changes.Changes[0].New) assert.Equal(t, "#/components/schemas/No", changes.Changes[0].New)
@@ -337,7 +336,7 @@ func TestCompareSchemas_RequiredAdded(t *testing.T) {
changes := CompareSchemas(lSchemaProxy, rSchemaProxy) changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.PropertyAdded, changes.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "two", changes.Changes[0].New) assert.Equal(t, "two", changes.Changes[0].New)
assert.Equal(t, v3.RequiredLabel, changes.Changes[0].Property) assert.Equal(t, v3.RequiredLabel, changes.Changes[0].Property)
} }
@@ -365,7 +364,7 @@ func TestCompareSchemas_RequiredRemoved(t *testing.T) {
changes := CompareSchemas(rSchemaProxy, lSchemaProxy) changes := CompareSchemas(rSchemaProxy, lSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.PropertyRemoved, changes.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "two", changes.Changes[0].Original) assert.Equal(t, "two", changes.Changes[0].Original)
assert.Equal(t, v3.RequiredLabel, changes.Changes[0].Property) assert.Equal(t, v3.RequiredLabel, changes.Changes[0].Property)
} }
@@ -390,7 +389,7 @@ func TestCompareSchemas_EnumAdded(t *testing.T) {
changes := CompareSchemas(lSchemaProxy, rSchemaProxy) changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.PropertyAdded, changes.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "d", changes.Changes[0].New) assert.Equal(t, "d", changes.Changes[0].New)
assert.Equal(t, v3.EnumLabel, changes.Changes[0].Property) assert.Equal(t, v3.EnumLabel, changes.Changes[0].Property)
} }
@@ -415,7 +414,7 @@ func TestCompareSchemas_EnumRemoved(t *testing.T) {
changes := CompareSchemas(rSchemaProxy, lSchemaProxy) changes := CompareSchemas(rSchemaProxy, lSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.PropertyRemoved, changes.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "d", changes.Changes[0].Original) assert.Equal(t, "d", changes.Changes[0].Original)
assert.Equal(t, v3.EnumLabel, changes.Changes[0].Property) assert.Equal(t, v3.EnumLabel, changes.Changes[0].Property)
} }
@@ -446,7 +445,7 @@ func TestCompareSchemas_PropertyAdded(t *testing.T) {
changes := CompareSchemas(lSchemaProxy, rSchemaProxy) changes := CompareSchemas(lSchemaProxy, rSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "propB", changes.Changes[0].New) assert.Equal(t, "propB", changes.Changes[0].New)
assert.Equal(t, v3.PropertiesLabel, changes.Changes[0].Property) assert.Equal(t, v3.PropertiesLabel, changes.Changes[0].Property)
} }
@@ -477,7 +476,7 @@ func TestCompareSchemas_PropertyRemoved(t *testing.T) {
changes := CompareSchemas(rSchemaProxy, lSchemaProxy) changes := CompareSchemas(rSchemaProxy, lSchemaProxy)
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Len(t, changes.Changes, 1) assert.Len(t, changes.Changes, 1)
assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "propB", changes.Changes[0].Original) assert.Equal(t, "propB", changes.Changes[0].Original)
assert.Equal(t, v3.PropertiesLabel, changes.Changes[0].Property) assert.Equal(t, v3.PropertiesLabel, changes.Changes[0].Property)
} }
@@ -507,7 +506,7 @@ func TestCompareSchemas_PropertyChanged(t *testing.T) {
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, core.Modified, changes.SchemaPropertyChanges["propA"].Changes[0].ChangeType) assert.Equal(t, Modified, changes.SchemaPropertyChanges["propA"].Changes[0].ChangeType)
assert.Equal(t, "string", changes.SchemaPropertyChanges["propA"].Changes[0].New) assert.Equal(t, "string", changes.SchemaPropertyChanges["propA"].Changes[0].New)
assert.Equal(t, "int", changes.SchemaPropertyChanges["propA"].Changes[0].Original) assert.Equal(t, "int", changes.SchemaPropertyChanges["propA"].Changes[0].Original)
} }
@@ -537,10 +536,10 @@ func TestCompareSchemas_PropertySwap(t *testing.T) {
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 2, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "propN", changes.Changes[0].New) assert.Equal(t, "propN", changes.Changes[0].New)
assert.Equal(t, v3.PropertiesLabel, changes.Changes[0].Property) assert.Equal(t, v3.PropertiesLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectRemoved, changes.Changes[1].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[1].ChangeType)
assert.Equal(t, "propA", changes.Changes[1].Original) assert.Equal(t, "propA", changes.Changes[1].Original)
assert.Equal(t, v3.PropertiesLabel, changes.Changes[1].Property) assert.Equal(t, v3.PropertiesLabel, changes.Changes[1].Property)
} }
@@ -569,9 +568,9 @@ func TestCompareSchemas_AnyOfModifyAndAddItem(t *testing.T) {
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 2, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, v3.AnyOfLabel, changes.Changes[0].Property) assert.Equal(t, v3.AnyOfLabel, changes.Changes[0].Property)
assert.Equal(t, core.Modified, changes.AnyOfChanges[0].Changes[0].ChangeType) assert.Equal(t, Modified, changes.AnyOfChanges[0].Changes[0].ChangeType)
assert.Equal(t, "string", changes.AnyOfChanges[0].Changes[0].New) assert.Equal(t, "string", changes.AnyOfChanges[0].Changes[0].New)
assert.Equal(t, "bool", changes.AnyOfChanges[0].Changes[0].Original) assert.Equal(t, "bool", changes.AnyOfChanges[0].Changes[0].Original)
} }
@@ -600,9 +599,9 @@ func TestCompareSchemas_AnyOfModifyAndRemoveItem(t *testing.T) {
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 2, changes.TotalChanges())
assert.Equal(t, 2, changes.TotalBreakingChanges()) assert.Equal(t, 2, changes.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, v3.AnyOfLabel, changes.Changes[0].Property) assert.Equal(t, v3.AnyOfLabel, changes.Changes[0].Property)
assert.Equal(t, core.Modified, changes.AnyOfChanges[0].Changes[0].ChangeType) assert.Equal(t, Modified, changes.AnyOfChanges[0].Changes[0].ChangeType)
assert.Equal(t, "bool", changes.AnyOfChanges[0].Changes[0].New) assert.Equal(t, "bool", changes.AnyOfChanges[0].Changes[0].New)
assert.Equal(t, "string", changes.AnyOfChanges[0].Changes[0].Original) assert.Equal(t, "string", changes.AnyOfChanges[0].Changes[0].Original)
} }
@@ -630,7 +629,7 @@ func TestCompareSchemas_AnyOfModified(t *testing.T) {
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, core.Modified, changes.AnyOfChanges[0].Changes[0].ChangeType) assert.Equal(t, Modified, changes.AnyOfChanges[0].Changes[0].ChangeType)
assert.Equal(t, "string", changes.AnyOfChanges[0].Changes[0].New) assert.Equal(t, "string", changes.AnyOfChanges[0].Changes[0].New)
assert.Equal(t, "bool", changes.AnyOfChanges[0].Changes[0].Original) assert.Equal(t, "bool", changes.AnyOfChanges[0].Changes[0].Original)
@@ -660,9 +659,9 @@ func TestCompareSchemas_OneOfModifyAndAddItem(t *testing.T) {
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 2, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, v3.OneOfLabel, changes.Changes[0].Property) assert.Equal(t, v3.OneOfLabel, changes.Changes[0].Property)
assert.Equal(t, core.Modified, changes.OneOfChanges[0].Changes[0].ChangeType) assert.Equal(t, Modified, changes.OneOfChanges[0].Changes[0].ChangeType)
assert.Equal(t, "string", changes.OneOfChanges[0].Changes[0].New) assert.Equal(t, "string", changes.OneOfChanges[0].Changes[0].New)
assert.Equal(t, "bool", changes.OneOfChanges[0].Changes[0].Original) assert.Equal(t, "bool", changes.OneOfChanges[0].Changes[0].Original)
} }
@@ -691,9 +690,9 @@ func TestCompareSchemas_AllOfModifyAndAddItem(t *testing.T) {
assert.NotNil(t, changes) assert.NotNil(t, changes)
assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 2, changes.TotalChanges())
assert.Equal(t, 2, changes.TotalBreakingChanges()) assert.Equal(t, 2, changes.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, v3.AllOfLabel, changes.Changes[0].Property) assert.Equal(t, v3.AllOfLabel, changes.Changes[0].Property)
assert.Equal(t, core.Modified, changes.AllOfChanges[0].Changes[0].ChangeType) assert.Equal(t, Modified, changes.AllOfChanges[0].Changes[0].ChangeType)
assert.Equal(t, "string", changes.AllOfChanges[0].Changes[0].New) assert.Equal(t, "string", changes.AllOfChanges[0].Changes[0].New)
assert.Equal(t, "bool", changes.AllOfChanges[0].Changes[0].Original) assert.Equal(t, "bool", changes.AllOfChanges[0].Changes[0].Original)
} }
@@ -724,7 +723,7 @@ func TestCompareSchemas_ItemsModifyAndAddItem(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.TypeLabel, changes.ItemsChanges[0].Changes[0].Property) assert.Equal(t, v3.TypeLabel, changes.ItemsChanges[0].Changes[0].Property)
assert.Equal(t, core.Modified, changes.ItemsChanges[0].Changes[0].ChangeType) assert.Equal(t, Modified, changes.ItemsChanges[0].Changes[0].ChangeType)
assert.Equal(t, "string", changes.ItemsChanges[0].Changes[0].New) assert.Equal(t, "string", changes.ItemsChanges[0].Changes[0].New)
assert.Equal(t, "bool", changes.ItemsChanges[0].Changes[0].Original) assert.Equal(t, "bool", changes.ItemsChanges[0].Changes[0].Original)
} }
@@ -755,7 +754,7 @@ func TestCompareSchemas_ItemsModifyAndAddItemArray(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.TypeLabel, changes.ItemsChanges[0].Changes[0].Property) assert.Equal(t, v3.TypeLabel, changes.ItemsChanges[0].Changes[0].Property)
assert.Equal(t, core.Modified, changes.ItemsChanges[0].Changes[0].ChangeType) assert.Equal(t, Modified, changes.ItemsChanges[0].Changes[0].ChangeType)
assert.Equal(t, "string", changes.ItemsChanges[0].Changes[0].New) assert.Equal(t, "string", changes.ItemsChanges[0].Changes[0].New)
assert.Equal(t, "bool", changes.ItemsChanges[0].Changes[0].Original) assert.Equal(t, "bool", changes.ItemsChanges[0].Changes[0].Original)
} }
@@ -786,7 +785,7 @@ func TestCompareSchemas_NotModifyAndAddItem(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.TypeLabel, changes.NotChanges[0].Changes[0].Property) assert.Equal(t, v3.TypeLabel, changes.NotChanges[0].Changes[0].Property)
assert.Equal(t, core.Modified, changes.NotChanges[0].Changes[0].ChangeType) assert.Equal(t, Modified, changes.NotChanges[0].Changes[0].ChangeType)
assert.Equal(t, "string", changes.NotChanges[0].Changes[0].New) assert.Equal(t, "string", changes.NotChanges[0].Changes[0].New)
assert.Equal(t, "bool", changes.NotChanges[0].Changes[0].Original) assert.Equal(t, "bool", changes.NotChanges[0].Changes[0].Original)
} }
@@ -817,7 +816,7 @@ func TestCompareSchemas_DiscriminatorChange(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.PropertyNameLabel, changes.DiscriminatorChanges.Changes[0].Property) assert.Equal(t, v3.PropertyNameLabel, changes.DiscriminatorChanges.Changes[0].Property)
assert.Equal(t, core.Modified, changes.DiscriminatorChanges.Changes[0].ChangeType) assert.Equal(t, Modified, changes.DiscriminatorChanges.Changes[0].ChangeType)
assert.Equal(t, "maddox", changes.DiscriminatorChanges.Changes[0].New) assert.Equal(t, "maddox", changes.DiscriminatorChanges.Changes[0].New)
assert.Equal(t, "melody", changes.DiscriminatorChanges.Changes[0].Original) assert.Equal(t, "melody", changes.DiscriminatorChanges.Changes[0].Original)
} }
@@ -846,7 +845,7 @@ func TestCompareSchemas_DiscriminatorAdd(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.DiscriminatorLabel, changes.Changes[0].Property) assert.Equal(t, v3.DiscriminatorLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "0e563831440581c713657dd857a0ec3af1bd7308a43bd3cae9184f61d61b288f", assert.Equal(t, "0e563831440581c713657dd857a0ec3af1bd7308a43bd3cae9184f61d61b288f",
low.HashToString(changes.Changes[0].NewObject.(*base.Discriminator).Hash())) low.HashToString(changes.Changes[0].NewObject.(*base.Discriminator).Hash()))
@@ -876,7 +875,7 @@ func TestCompareSchemas_DiscriminatorRemove(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.DiscriminatorLabel, changes.Changes[0].Property) assert.Equal(t, v3.DiscriminatorLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "0e563831440581c713657dd857a0ec3af1bd7308a43bd3cae9184f61d61b288f", assert.Equal(t, "0e563831440581c713657dd857a0ec3af1bd7308a43bd3cae9184f61d61b288f",
low.HashToString(changes.Changes[0].OriginalObject.(*base.Discriminator).Hash())) low.HashToString(changes.Changes[0].OriginalObject.(*base.Discriminator).Hash()))
@@ -908,7 +907,7 @@ func TestCompareSchemas_ExternalDocsChange(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.URLLabel, changes.ExternalDocChanges.Changes[0].Property) assert.Equal(t, v3.URLLabel, changes.ExternalDocChanges.Changes[0].Property)
assert.Equal(t, core.Modified, changes.ExternalDocChanges.Changes[0].ChangeType) assert.Equal(t, Modified, changes.ExternalDocChanges.Changes[0].ChangeType)
assert.Equal(t, "https://pb33f.io/new", changes.ExternalDocChanges.Changes[0].New) assert.Equal(t, "https://pb33f.io/new", changes.ExternalDocChanges.Changes[0].New)
assert.Equal(t, "https://pb33f.io", changes.ExternalDocChanges.Changes[0].Original) assert.Equal(t, "https://pb33f.io", changes.ExternalDocChanges.Changes[0].Original)
} }
@@ -937,7 +936,7 @@ func TestCompareSchemas_ExternalDocsAdd(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExternalDocsLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExternalDocsLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "2b7adf30f2ea3a7617ccf429a099617a9c03e8b5f3a23a89dba4b90f760010d7", assert.Equal(t, "2b7adf30f2ea3a7617ccf429a099617a9c03e8b5f3a23a89dba4b90f760010d7",
low.HashToString(changes.Changes[0].NewObject.(*base.ExternalDoc).Hash())) low.HashToString(changes.Changes[0].NewObject.(*base.ExternalDoc).Hash()))
@@ -967,7 +966,7 @@ func TestCompareSchemas_ExternalDocsRemove(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExternalDocsLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExternalDocsLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "2b7adf30f2ea3a7617ccf429a099617a9c03e8b5f3a23a89dba4b90f760010d7", assert.Equal(t, "2b7adf30f2ea3a7617ccf429a099617a9c03e8b5f3a23a89dba4b90f760010d7",
low.HashToString(changes.Changes[0].OriginalObject.(*base.ExternalDoc).Hash())) low.HashToString(changes.Changes[0].OriginalObject.(*base.ExternalDoc).Hash()))
@@ -996,7 +995,7 @@ func TestCompareSchemas_AddExtension(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, "x-melody", changes.ExtensionChanges.Changes[0].Property) assert.Equal(t, "x-melody", changes.ExtensionChanges.Changes[0].Property)
assert.Equal(t, core.ObjectAdded, changes.ExtensionChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.ExtensionChanges.Changes[0].ChangeType)
assert.Equal(t, "song", changes.ExtensionChanges.Changes[0].New) assert.Equal(t, "song", changes.ExtensionChanges.Changes[0].New)
} }
@@ -1022,7 +1021,7 @@ func TestCompareSchemas_ExampleChange(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExampleLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExampleLabel, changes.Changes[0].Property)
assert.Equal(t, core.Modified, changes.Changes[0].ChangeType) assert.Equal(t, Modified, changes.Changes[0].ChangeType)
assert.Equal(t, "yellow boat", changes.Changes[0].New) assert.Equal(t, "yellow boat", changes.Changes[0].New)
assert.Equal(t, "sausages", changes.Changes[0].Original) assert.Equal(t, "sausages", changes.Changes[0].Original)
} }
@@ -1050,7 +1049,7 @@ func TestCompareSchemas_ExampleAdd(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExampleLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExampleLabel, changes.Changes[0].Property)
assert.Equal(t, core.PropertyAdded, changes.Changes[0].ChangeType) assert.Equal(t, PropertyAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "yellow boat", changes.Changes[0].New) assert.Equal(t, "yellow boat", changes.Changes[0].New)
} }
@@ -1077,7 +1076,7 @@ func TestCompareSchemas_ExampleRemove(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExampleLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExampleLabel, changes.Changes[0].Property)
assert.Equal(t, core.PropertyRemoved, changes.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "yellow boat", changes.Changes[0].Original) assert.Equal(t, "yellow boat", changes.Changes[0].Original)
} }
@@ -1107,7 +1106,7 @@ func TestCompareSchemas_ExamplesChange(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property)
assert.Equal(t, core.Modified, changes.Changes[0].ChangeType) assert.Equal(t, Modified, changes.Changes[0].ChangeType)
assert.Equal(t, "yellow boat", changes.Changes[0].New) assert.Equal(t, "yellow boat", changes.Changes[0].New)
assert.Equal(t, "sausages", changes.Changes[0].Original) assert.Equal(t, "sausages", changes.Changes[0].Original)
} }
@@ -1136,7 +1135,7 @@ func TestCompareSchemas_ExamplesAdd(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "yellow boat", changes.Changes[0].New) assert.Equal(t, "yellow boat", changes.Changes[0].New)
} }
@@ -1167,10 +1166,10 @@ func TestCompareSchemas_ExamplesAddAndModify(t *testing.T) {
assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 2, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property)
assert.Equal(t, core.Modified, changes.Changes[0].ChangeType) assert.Equal(t, Modified, changes.Changes[0].ChangeType)
assert.Equal(t, "yellow boat", changes.Changes[0].New) assert.Equal(t, "yellow boat", changes.Changes[0].New)
assert.Equal(t, "sausages", changes.Changes[0].Original) assert.Equal(t, "sausages", changes.Changes[0].Original)
assert.Equal(t, core.ObjectAdded, changes.Changes[1].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[1].ChangeType)
assert.Equal(t, "seal pup", changes.Changes[1].New) assert.Equal(t, "seal pup", changes.Changes[1].New)
} }
@@ -1198,7 +1197,7 @@ func TestCompareSchemas_ExamplesRemove(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "yellow boat", changes.Changes[0].Original) assert.Equal(t, "yellow boat", changes.Changes[0].Original)
} }
@@ -1229,10 +1228,10 @@ func TestCompareSchemas_ExamplesRemoveAndModify(t *testing.T) {
assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 2, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property) assert.Equal(t, v3.ExamplesLabel, changes.Changes[0].Property)
assert.Equal(t, core.Modified, changes.Changes[0].ChangeType) assert.Equal(t, Modified, changes.Changes[0].ChangeType)
assert.Equal(t, "yellow boat", changes.Changes[0].Original) assert.Equal(t, "yellow boat", changes.Changes[0].Original)
assert.Equal(t, "sausages", changes.Changes[0].New) assert.Equal(t, "sausages", changes.Changes[0].New)
assert.Equal(t, core.ObjectRemoved, changes.Changes[1].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[1].ChangeType)
assert.Equal(t, "seal pup", changes.Changes[1].Original) assert.Equal(t, "seal pup", changes.Changes[1].Original)
} }
@@ -1260,7 +1259,7 @@ func TestCompareSchemas_XMLChange(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.NameLabel, changes.XMLChanges.Changes[0].Property) assert.Equal(t, v3.NameLabel, changes.XMLChanges.Changes[0].Property)
assert.Equal(t, core.Modified, changes.XMLChanges.Changes[0].ChangeType) assert.Equal(t, Modified, changes.XMLChanges.Changes[0].ChangeType)
assert.Equal(t, "big xml", changes.XMLChanges.Changes[0].New) assert.Equal(t, "big xml", changes.XMLChanges.Changes[0].New)
assert.Equal(t, "baby xml", changes.XMLChanges.Changes[0].Original) assert.Equal(t, "baby xml", changes.XMLChanges.Changes[0].Original)
} }
@@ -1289,7 +1288,7 @@ func TestCompareSchemas_XMLAdd(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges())
assert.Equal(t, v3.XMLLabel, changes.Changes[0].Property) assert.Equal(t, v3.XMLLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectAdded, changes.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[0].ChangeType)
assert.Equal(t, "big xml", changes.Changes[0].NewObject.(*base.XML).Name.Value) assert.Equal(t, "big xml", changes.Changes[0].NewObject.(*base.XML).Name.Value)
} }
@@ -1315,6 +1314,6 @@ func TestCompareSchemas_XMLRemove(t *testing.T) {
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
assert.Equal(t, v3.XMLLabel, changes.Changes[0].Property) assert.Equal(t, v3.XMLLabel, changes.Changes[0].Property)
assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, "big xml", changes.Changes[0].OriginalObject.(*base.XML).Name.Value) assert.Equal(t, "big xml", changes.Changes[0].OriginalObject.(*base.XML).Name.Value)
} }

View File

@@ -7,12 +7,11 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v2"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
type SecurityRequirementChanges struct { type SecurityRequirementChanges struct {
core.PropertyChanges PropertyChanges
} }
func (s *SecurityRequirementChanges) TotalChanges() int { func (s *SecurityRequirementChanges) TotalChanges() int {
@@ -27,7 +26,7 @@ func CompareSecurityRequirement(l, r *v2.SecurityRequirement) *SecurityRequireme
if low.AreEqual(l, r) { if low.AreEqual(l, r) {
return nil return nil
} }
var changes []*core.Change var changes []*Change
lKeys := make([]string, len(l.Values.Value)) lKeys := make([]string, len(l.Values.Value))
rKeys := make([]string, len(r.Values.Value)) rKeys := make([]string, len(r.Values.Value))
lValues := make(map[string]low.ValueReference[[]low.ValueReference[string]]) lValues := make(map[string]low.ValueReference[[]low.ValueReference[string]])
@@ -44,12 +43,12 @@ func CompareSecurityRequirement(l, r *v2.SecurityRequirement) *SecurityRequireme
z++ z++
} }
removed := func(z int, vn *yaml.Node, name string) { removed := func(z int, vn *yaml.Node, name string) {
core.CreateChange(&changes, core.ObjectRemoved, v3.SecurityDefinitionLabel, CreateChange(&changes, ObjectRemoved, v3.SecurityDefinitionLabel,
vn, nil, true, name, nil) vn, nil, true, name, nil)
} }
added := func(z int, vn *yaml.Node, name string) { added := func(z int, vn *yaml.Node, name string) {
core.CreateChange(&changes, core.ObjectAdded, v3.SecurityDefinitionLabel, CreateChange(&changes, ObjectAdded, v3.SecurityDefinitionLabel,
nil, vn, false, nil, name) nil, vn, false, nil, name)
} }

View File

@@ -6,7 +6,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v2"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -71,7 +70,7 @@ biscuit:
extChanges := CompareSecurityRequirement(&lDoc, &rDoc) extChanges := CompareSecurityRequirement(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, "biscuit", extChanges.Changes[0].NewObject) assert.Equal(t, "biscuit", extChanges.Changes[0].NewObject)
} }
@@ -135,10 +134,10 @@ milk:
extChanges := CompareSecurityRequirement(&lDoc, &rDoc) extChanges := CompareSecurityRequirement(&lDoc, &rDoc)
assert.Equal(t, 4, extChanges.TotalChanges()) assert.Equal(t, 4, extChanges.TotalChanges())
assert.Equal(t, 2, extChanges.TotalBreakingChanges()) assert.Equal(t, 2, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[1].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[1].ChangeType)
assert.Equal(t, core.ObjectAdded, extChanges.Changes[2].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[2].ChangeType)
assert.Equal(t, core.ObjectAdded, extChanges.Changes[3].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[3].ChangeType)
} }
func TestCompareSecurityRequirement_SwapLeft(t *testing.T) { func TestCompareSecurityRequirement_SwapLeft(t *testing.T) {
@@ -171,8 +170,8 @@ milk:
extChanges := CompareSecurityRequirement(&lDoc, &rDoc) extChanges := CompareSecurityRequirement(&lDoc, &rDoc)
assert.Equal(t, 2, extChanges.TotalChanges()) assert.Equal(t, 2, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, core.ObjectAdded, extChanges.Changes[1].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[1].ChangeType)
} }
func TestCompareSecurityRequirement_AddedRole(t *testing.T) { func TestCompareSecurityRequirement_AddedRole(t *testing.T) {
@@ -206,7 +205,7 @@ biscuit:
extChanges := CompareSecurityRequirement(&lDoc, &rDoc) extChanges := CompareSecurityRequirement(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
assert.Equal(t, "rich tea", extChanges.Changes[0].New) assert.Equal(t, "rich tea", extChanges.Changes[0].New)
} }
@@ -244,7 +243,7 @@ biscuit:
extChanges := CompareSecurityRequirement(&lDoc, &rDoc) extChanges := CompareSecurityRequirement(&lDoc, &rDoc)
assert.Equal(t, 2, extChanges.TotalChanges()) assert.Equal(t, 2, extChanges.TotalChanges())
assert.Equal(t, 0, extChanges.TotalBreakingChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectAdded, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.Changes[0].ChangeType)
} }
func TestCompareSecurityRequirement_ReplaceRole(t *testing.T) { func TestCompareSecurityRequirement_ReplaceRole(t *testing.T) {
@@ -344,6 +343,6 @@ biscuit:
extChanges := CompareSecurityRequirement(&rDoc, &lDoc) extChanges := CompareSecurityRequirement(&rDoc, &lDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, "rich tea", extChanges.Changes[0].Original) assert.Equal(t, "rich tea", extChanges.Changes[0].Original)
} }

View File

@@ -7,13 +7,12 @@ import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"strings" "strings"
) )
// TagChanges represents changes made to the Tags object of an OpenAPI document. // TagChanges represents changes made to the Tags object of an OpenAPI document.
type TagChanges struct { type TagChanges struct {
core.PropertyChanges PropertyChanges
ExternalDocs *ExternalDocChanges ExternalDocs *ExternalDocChanges
ExtensionChanges *ExtensionChanges ExtensionChanges *ExtensionChanges
} }
@@ -53,20 +52,20 @@ func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges {
seenRight[strings.ToLower(r[i].Value.Name.Value)] = &h seenRight[strings.ToLower(r[i].Value.Name.Value)] = &h
} }
var changes []*core.Change var changes []*Change
// check for removals, modifications and moves // check for removals, modifications and moves
for i := range seenLeft { for i := range seenLeft {
core.CheckForObjectAdditionOrRemoval[*base.Tag](seenLeft, seenRight, i, &changes, false, true) CheckForObjectAdditionOrRemoval[*base.Tag](seenLeft, seenRight, i, &changes, false, true)
// if the existing tag exists, let's check it. // if the existing tag exists, let's check it.
if seenRight[i] != nil { if seenRight[i] != nil {
var props []*core.PropertyCheck var props []*PropertyCheck
// Name // Name
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: seenLeft[i].Value.Name.ValueNode, LeftNode: seenLeft[i].Value.Name.ValueNode,
RightNode: seenRight[i].Value.Name.ValueNode, RightNode: seenRight[i].Value.Name.ValueNode,
Label: v3.NameLabel, Label: v3.NameLabel,
@@ -77,7 +76,7 @@ func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges {
}) })
// Description // Description
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: seenLeft[i].Value.Description.ValueNode, LeftNode: seenLeft[i].Value.Description.ValueNode,
RightNode: seenRight[i].Value.Description.ValueNode, RightNode: seenRight[i].Value.Description.ValueNode,
Label: v3.DescriptionLabel, Label: v3.DescriptionLabel,
@@ -88,7 +87,7 @@ func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges {
}) })
// check properties // check properties
core.CheckProperties(props) CheckProperties(props)
// compare external docs // compare external docs
tc.ExternalDocs = CompareExternalDocs(seenLeft[i].Value.ExternalDocs.Value, tc.ExternalDocs = CompareExternalDocs(seenLeft[i].Value.ExternalDocs.Value,
@@ -102,7 +101,7 @@ func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges {
for i := range seenRight { for i := range seenRight {
if seenLeft[i] == nil { if seenLeft[i] == nil {
core.CreateChange(&changes, core.ObjectAdded, i, nil, seenRight[i].GetValueNode(), CreateChange(&changes, ObjectAdded, i, nil, seenRight[i].GetValueNode(),
false, nil, seenRight[i].GetValue()) false, nil, seenRight[i].GetValue())
} }
} }

View File

@@ -6,7 +6,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel" "github.com/pb33f/libopenapi/datamodel"
lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3" lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing" "testing"
) )
@@ -49,7 +48,7 @@ tags:
descChange := changes.Changes[0] descChange := changes.Changes[0]
assert.Equal(t, "a lovelier tag description", descChange.New) assert.Equal(t, "a lovelier tag description", descChange.New)
assert.Equal(t, "a lovely tag", descChange.Original) assert.Equal(t, "a lovely tag", descChange.Original)
assert.Equal(t, core.Modified, descChange.ChangeType) assert.Equal(t, Modified, descChange.ChangeType)
assert.False(t, descChange.Context.HasChanged()) assert.False(t, descChange.Context.HasChanged())
} }
@@ -89,7 +88,7 @@ tags:
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
descChange := changes.Changes[0] descChange := changes.Changes[0]
assert.Equal(t, core.ObjectAdded, descChange.ChangeType) assert.Equal(t, ObjectAdded, descChange.ChangeType)
} }
func TestCompareTags_AddDeleteTag(t *testing.T) { func TestCompareTags_AddDeleteTag(t *testing.T) {
@@ -121,8 +120,8 @@ tags:
assert.Len(t, changes.Changes, 2) assert.Len(t, changes.Changes, 2)
assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 2, changes.TotalChanges())
assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType)
assert.Equal(t, core.ObjectAdded, changes.Changes[1].ChangeType) assert.Equal(t, ObjectAdded, changes.Changes[1].ChangeType)
assert.Equal(t, 1, changes.TotalBreakingChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges())
} }
@@ -227,7 +226,7 @@ tags:
assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalChanges())
descChange := changes.Changes[0] descChange := changes.Changes[0]
assert.Equal(t, core.Modified, descChange.ChangeType) assert.Equal(t, Modified, descChange.ChangeType)
assert.Equal(t, "a lovelier tag description", descChange.Original) assert.Equal(t, "a lovelier tag description", descChange.Original)
assert.Equal(t, "a different tag description", descChange.New) assert.Equal(t, "a different tag description", descChange.New)
assert.True(t, descChange.Context.HasChanged()) assert.True(t, descChange.Context.HasChanged())

View File

@@ -6,12 +6,11 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/core"
) )
// XMLChanges represents changes made to the XML object of an OpenAPI document. // XMLChanges represents changes made to the XML object of an OpenAPI document.
type XMLChanges struct { type XMLChanges struct {
core.PropertyChanges PropertyChanges
ExtensionChanges *ExtensionChanges ExtensionChanges *ExtensionChanges
} }
@@ -34,11 +33,11 @@ func (x *XMLChanges) TotalBreakingChanges() int {
// otherwise, if nothing changed - it will return nil // otherwise, if nothing changed - it will return nil
func CompareXML(l, r *base.XML) *XMLChanges { func CompareXML(l, r *base.XML) *XMLChanges {
xc := new(XMLChanges) xc := new(XMLChanges)
var changes []*core.Change var changes []*Change
var props []*core.PropertyCheck var props []*PropertyCheck
// Name (breaking change) // Name (breaking change)
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Name.ValueNode, LeftNode: l.Name.ValueNode,
RightNode: r.Name.ValueNode, RightNode: r.Name.ValueNode,
Label: v3.NameLabel, Label: v3.NameLabel,
@@ -49,7 +48,7 @@ func CompareXML(l, r *base.XML) *XMLChanges {
}) })
// Namespace (breaking change) // Namespace (breaking change)
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Namespace.ValueNode, LeftNode: l.Namespace.ValueNode,
RightNode: r.Namespace.ValueNode, RightNode: r.Namespace.ValueNode,
Label: v3.NamespaceLabel, Label: v3.NamespaceLabel,
@@ -60,7 +59,7 @@ func CompareXML(l, r *base.XML) *XMLChanges {
}) })
// Prefix (breaking change) // Prefix (breaking change)
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Prefix.ValueNode, LeftNode: l.Prefix.ValueNode,
RightNode: r.Prefix.ValueNode, RightNode: r.Prefix.ValueNode,
Label: v3.PrefixLabel, Label: v3.PrefixLabel,
@@ -71,7 +70,7 @@ func CompareXML(l, r *base.XML) *XMLChanges {
}) })
// Attribute (breaking change) // Attribute (breaking change)
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Attribute.ValueNode, LeftNode: l.Attribute.ValueNode,
RightNode: r.Attribute.ValueNode, RightNode: r.Attribute.ValueNode,
Label: v3.AttributeLabel, Label: v3.AttributeLabel,
@@ -82,7 +81,7 @@ func CompareXML(l, r *base.XML) *XMLChanges {
}) })
// Wrapped (breaking change) // Wrapped (breaking change)
props = append(props, &core.PropertyCheck{ props = append(props, &PropertyCheck{
LeftNode: l.Wrapped.ValueNode, LeftNode: l.Wrapped.ValueNode,
RightNode: r.Wrapped.ValueNode, RightNode: r.Wrapped.ValueNode,
Label: v3.WrappedLabel, Label: v3.WrappedLabel,
@@ -93,7 +92,7 @@ func CompareXML(l, r *base.XML) *XMLChanges {
}) })
// check properties // check properties
core.CheckProperties(props) CheckProperties(props)
// check extensions // check extensions
xc.ExtensionChanges = CheckExtensions(l, r) xc.ExtensionChanges = CheckExtensions(l, r)

View File

@@ -6,7 +6,6 @@ package model
import ( import (
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/what-changed/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"testing" "testing"
@@ -41,7 +40,7 @@ wrapped: true`
// compare. // compare.
extChanges := CompareXML(&lDoc, &rDoc) extChanges := CompareXML(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType)
} }
@@ -73,7 +72,7 @@ namespace: something`
// compare. // compare.
extChanges := CompareXML(&lDoc, &rDoc) extChanges := CompareXML(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType)
assert.Equal(t, 1, extChanges.TotalBreakingChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges())
} }
@@ -108,7 +107,7 @@ x-coffee: time`
// compare. // compare.
extChanges := CompareXML(&lDoc, &rDoc) extChanges := CompareXML(&lDoc, &rDoc)
assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalChanges())
assert.Equal(t, core.ObjectAdded, extChanges.ExtensionChanges.Changes[0].ChangeType) assert.Equal(t, ObjectAdded, extChanges.ExtensionChanges.Changes[0].ChangeType)
} }