From fcd4a0f57d25b3beeb2e2ed94c9d3adefd938bcd Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Sun, 23 Oct 2022 12:14:31 -0400 Subject: [PATCH] Refactoring the what-changed again I cannot pull these models apart, they are too inter-connected and imports will cycle. --- datamodel/low/v2/header.go | 48 +++++++ datamodel/low/v3/security_scheme.go | 7 + what-changed/{core => model}/change_types.go | 2 +- .../{core => model}/comparison_functions.go | 2 +- what-changed/model/contact.go | 15 +-- what-changed/model/contact_test.go | 15 +-- what-changed/model/discriminator.go | 27 ++-- what-changed/model/discriminator_test.go | 19 ++- what-changed/model/encoding.go | 15 +-- what-changed/model/encoding_test.go | 3 +- what-changed/model/example.go | 17 ++- what-changed/model/example_test.go | 7 +- what-changed/model/extensions.go | 15 +-- what-changed/model/extensions_test.go | 7 +- what-changed/model/external_docs.go | 13 +- what-changed/model/external_docs_test.go | 21 ++- what-changed/model/header.go | 43 +++--- what-changed/model/header_test.go | 5 +- what-changed/model/info.go | 25 ++-- what-changed/model/info_test.go | 19 ++- what-changed/model/items.go | 13 +- what-changed/model/items_test.go | 5 +- what-changed/model/license.go | 13 +- what-changed/model/license_test.go | 15 +-- what-changed/model/media_type.go | 17 ++- what-changed/model/media_type_test.go | 7 +- what-changed/model/parameter.go | 49 ++++--- what-changed/model/parameter_test.go | 27 ++-- what-changed/model/schema.go | 125 +++++++++--------- what-changed/model/schema_test.go | 99 +++++++------- what-changed/model/security_requirement.go | 9 +- .../model/security_requirement_test.go | 21 ++- what-changed/model/tags.go | 17 ++- what-changed/model/tags_test.go | 11 +- what-changed/model/xml.go | 19 ++- what-changed/model/xml_test.go | 7 +- 36 files changed, 407 insertions(+), 372 deletions(-) rename what-changed/{core => model}/change_types.go (99%) rename what-changed/{core => model}/comparison_functions.go (99%) diff --git a/datamodel/low/v2/header.go b/datamodel/low/v2/header.go index 7ed7c47..1286400 100644 --- a/datamodel/low/v2/header.go +++ b/datamodel/low/v2/header.go @@ -4,10 +4,13 @@ package v2 import ( + "crypto/sha256" + "fmt" "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/index" "github.com/pb33f/libopenapi/utils" "gopkg.in/yaml.v3" + "strings" ) // 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 } +// 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 func (h *Header) GetType() *low.NodeReference[string] { diff --git a/datamodel/low/v3/security_scheme.go b/datamodel/low/v3/security_scheme.go index f953542..5d847df 100644 --- a/datamodel/low/v3/security_scheme.go +++ b/datamodel/low/v3/security_scheme.go @@ -4,10 +4,12 @@ package v3 import ( + "crypto/sha256" "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/index" "github.com/pb33f/libopenapi/utils" "gopkg.in/yaml.v3" + "strings" ) // 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 } +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. func (sr *SecurityRequirement) FindRequirement(name string) []low.ValueReference[string] { for _, r := range sr.ValueRequirements { diff --git a/what-changed/core/change_types.go b/what-changed/model/change_types.go similarity index 99% rename from what-changed/core/change_types.go rename to what-changed/model/change_types.go index e0a3aa2..5762446 100644 --- a/what-changed/core/change_types.go +++ b/what-changed/model/change_types.go @@ -1,7 +1,7 @@ // Copyright 2022 Princess B33f Heavy Industries / Dave Shanley // SPDX-License-Identifier: MIT -package core +package model import ( "gopkg.in/yaml.v3" diff --git a/what-changed/core/comparison_functions.go b/what-changed/model/comparison_functions.go similarity index 99% rename from what-changed/core/comparison_functions.go rename to what-changed/model/comparison_functions.go index 3373f4a..32419bc 100644 --- a/what-changed/core/comparison_functions.go +++ b/what-changed/model/comparison_functions.go @@ -1,7 +1,7 @@ // Copyright 2022 Princess B33f Heavy Industries / Dave Shanley // SPDX-License-Identifier: MIT -package core +package model import ( "github.com/pb33f/libopenapi/datamodel/low" diff --git a/what-changed/model/contact.go b/what-changed/model/contact.go index 306f88a..fefda3d 100644 --- a/what-changed/model/contact.go +++ b/what-changed/model/contact.go @@ -6,12 +6,11 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low/base" "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. type ContactChanges struct { - core.PropertyChanges + PropertyChanges } // 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. func CompareContact(l, r *base.Contact) *ContactChanges { - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck // check URL - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.URL.ValueNode, RightNode: r.URL.ValueNode, Label: v3.URLLabel, @@ -44,7 +43,7 @@ func CompareContact(l, r *base.Contact) *ContactChanges { }) // check name - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Name.ValueNode, RightNode: r.Name.ValueNode, Label: v3.NameLabel, @@ -55,7 +54,7 @@ func CompareContact(l, r *base.Contact) *ContactChanges { }) // check email - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Email.ValueNode, RightNode: r.Email.ValueNode, Label: v3.EmailLabel, @@ -66,7 +65,7 @@ func CompareContact(l, r *base.Contact) *ContactChanges { }) // check everything. - core.CheckProperties(props) + CheckProperties(props) dc := new(ContactChanges) dc.Changes = changes diff --git a/what-changed/model/contact_test.go b/what-changed/model/contact_test.go index a498a1f..58961b2 100644 --- a/what-changed/model/contact_test.go +++ b/what-changed/model/contact_test.go @@ -6,7 +6,6 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low" lowbase "github.com/pb33f/libopenapi/datamodel/low/base" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -34,7 +33,7 @@ url: https://pb33f.io` // compare. extChanges := CompareContact(&lDoc, &rDoc) 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. extChanges := CompareContact(&lDoc, &rDoc) 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. extChanges := CompareContact(&lDoc, &rDoc) 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. extChanges := CompareContact(&lDoc, &rDoc) 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) { @@ -137,7 +136,7 @@ email: buckaroo@pb33f.io` // compare. extChanges := CompareContact(&lDoc, &rDoc) 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. extChanges := CompareContact(&lDoc, &rDoc) 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) { @@ -189,7 +188,7 @@ email: dave@quobix.com` // compare. extChanges := CompareContact(&lDoc, &rDoc) 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()) } diff --git a/what-changed/model/discriminator.go b/what-changed/model/discriminator.go index 9831a24..5e01fe0 100644 --- a/what-changed/model/discriminator.go +++ b/what-changed/model/discriminator.go @@ -6,13 +6,12 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low/base" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" ) // DiscriminatorChanges represents changes made to a Discriminator OpenAPI object type DiscriminatorChanges struct { - core.PropertyChanges - MappingChanges []*core.Change + PropertyChanges + MappingChanges []*Change } // 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 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 // and will return a pointer to DiscriminatorChanges func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges { dc := new(DiscriminatorChanges) - var changes []*core.Change - var props []*core.PropertyCheck - var mappingChanges []*core.Change + var changes []*Change + var props []*PropertyCheck + var mappingChanges []*Change // Name (breaking change) - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.PropertyName.ValueNode, RightNode: r.PropertyName.ValueNode, Label: v3.PropertyNameLabel, @@ -52,19 +51,19 @@ func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges { }) // check properties - core.CheckProperties(props) + CheckProperties(props) // flatten maps - lMap := core.FlattenLowLevelMap[string](l.Mapping) - rMap := core.FlattenLowLevelMap[string](r.Mapping) + lMap := FlattenLowLevelMap[string](l.Mapping) + rMap := FlattenLowLevelMap[string](r.Mapping) // check for removals, modifications and moves 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 rMap[i] != nil { 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()) } } @@ -72,7 +71,7 @@ func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges { for i := range rMap { if lMap[i] == nil { - core.CreateChange(&mappingChanges, core.ObjectAdded, i, nil, + CreateChange(&mappingChanges, ObjectAdded, i, nil, rMap[i].GetValueNode(), false, nil, rMap[i].GetValue()) } } diff --git a/what-changed/model/discriminator_test.go b/what-changed/model/discriminator_test.go index 3092404..0e7d6ac 100644 --- a/what-changed/model/discriminator_test.go +++ b/what-changed/model/discriminator_test.go @@ -6,7 +6,6 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/base" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -31,7 +30,7 @@ func TestCompareDiscriminator_PropertyNameChanged(t *testing.T) { // compare. extChanges := CompareDiscriminator(&lDoc, &rDoc) 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. extChanges := CompareDiscriminator(&lDoc, &rDoc) 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) { @@ -76,7 +75,7 @@ func TestCompareDiscriminator_PropertyNameAdded(t *testing.T) { // compare. extChanges := CompareDiscriminator(&lDoc, &rDoc) 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) { @@ -103,7 +102,7 @@ mapping: assert.Equal(t, 2, extChanges.TotalChanges()) for _, k := range extChanges.MappingChanges { - assert.Equal(t, core.ObjectAdded, k.ChangeType) + assert.Equal(t, ObjectAdded, k.ChangeType) if k.Property == "chuffing" { assert.Equal(t, "puffing", k.New) } @@ -137,7 +136,7 @@ mapping: // compare. extChanges := CompareDiscriminator(&lDoc, &rDoc) 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, "puffing", extChanges.MappingChanges[0].Original) } @@ -166,7 +165,7 @@ mapping: // compare. extChanges := CompareDiscriminator(&lDoc, &rDoc) 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, "coding", extChanges.MappingChanges[0].New) @@ -197,10 +196,10 @@ mapping: // compare. extChanges := CompareDiscriminator(&lDoc, &rDoc) 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 { - assert.Equal(t, core.ObjectAdded, k.ChangeType) + assert.Equal(t, ObjectAdded, k.ChangeType) if k.Property == "hacking" { assert.Equal(t, "coding", k.New) } @@ -233,7 +232,7 @@ mapping: // compare. extChanges := CompareDiscriminator(&lDoc, &rDoc) 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, "herbs", extChanges.MappingChanges[0].New) assert.Equal(t, "puffing", extChanges.MappingChanges[0].Original) diff --git a/what-changed/model/encoding.go b/what-changed/model/encoding.go index 5e944c1..ed0649e 100644 --- a/what-changed/model/encoding.go +++ b/what-changed/model/encoding.go @@ -5,7 +5,6 @@ package model import ( v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" ) type EncodingChanges struct { @@ -35,11 +34,11 @@ func (e *EncodingChanges) TotalBreakingChanges() int { func CompareEncoding(l, r *v3.Encoding) *EncodingChanges { - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck // ContentType - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.ContentType.ValueNode, RightNode: r.ContentType.ValueNode, Label: v3.ContentTypeLabel, @@ -50,7 +49,7 @@ func CompareEncoding(l, r *v3.Encoding) *EncodingChanges { }) // Explode - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Explode.ValueNode, RightNode: r.Explode.ValueNode, Label: v3.ExplodeLabel, @@ -61,7 +60,7 @@ func CompareEncoding(l, r *v3.Encoding) *EncodingChanges { }) // AllowReserved - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.AllowReserved.ValueNode, RightNode: r.AllowReserved.ValueNode, Label: v3.AllowReservedLabel, @@ -72,11 +71,11 @@ func CompareEncoding(l, r *v3.Encoding) *EncodingChanges { }) // check everything. - core.CheckProperties(props) + CheckProperties(props) ec := new(EncodingChanges) // 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 if ec.TotalChanges() <= 0 { return nil diff --git a/what-changed/model/encoding_test.go b/what-changed/model/encoding_test.go index e6a834f..698ce48 100644 --- a/what-changed/model/encoding_test.go +++ b/what-changed/model/encoding_test.go @@ -6,7 +6,6 @@ package model import ( "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" "gopkg.in/yaml.v3" "testing" @@ -116,7 +115,7 @@ allowReserved: true` assert.NotNil(t, extChanges) assert.Equal(t, 1, extChanges.TotalChanges()) 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) } diff --git a/what-changed/model/example.go b/what-changed/model/example.go index 961494d..715e283 100644 --- a/what-changed/model/example.go +++ b/what-changed/model/example.go @@ -6,12 +6,11 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low/base" 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. type ExampleChanges struct { - core.PropertyChanges + PropertyChanges ExtensionChanges *ExtensionChanges } @@ -35,11 +34,11 @@ func (e *ExampleChanges) TotalBreakingChanges() int { func CompareExamples(l, r *base.Example) *ExampleChanges { ec := new(ExampleChanges) - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck // Summary - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Summary.ValueNode, RightNode: r.Summary.ValueNode, Label: v3.SummaryLabel, @@ -50,7 +49,7 @@ func CompareExamples(l, r *base.Example) *ExampleChanges { }) // Description - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Description.ValueNode, RightNode: r.Description.ValueNode, Label: v3.DescriptionLabel, @@ -61,7 +60,7 @@ func CompareExamples(l, r *base.Example) *ExampleChanges { }) // Value - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Value.ValueNode, RightNode: r.Value.ValueNode, Label: v3.ValueLabel, @@ -72,7 +71,7 @@ func CompareExamples(l, r *base.Example) *ExampleChanges { }) // ExternalValue - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.ExternalValue.ValueNode, RightNode: r.ExternalValue.ValueNode, Label: v3.ExternalValue, @@ -83,7 +82,7 @@ func CompareExamples(l, r *base.Example) *ExampleChanges { }) // check properties - core.CheckProperties(props) + CheckProperties(props) // check extensions ec.ExtensionChanges = CheckExtensions(l, r) diff --git a/what-changed/model/example_test.go b/what-changed/model/example_test.go index 7319a14..d8c3720 100644 --- a/what-changed/model/example_test.go +++ b/what-changed/model/example_test.go @@ -7,7 +7,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/base" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -34,7 +33,7 @@ func TestCompareExamples_SummaryModified(t *testing.T) { assert.Equal(t, extChanges.TotalChanges(), 1) 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, "magic herbs", extChanges.Changes[0].Original) assert.Equal(t, "cure all", extChanges.Changes[0].New) @@ -61,7 +60,7 @@ description: cure all` extChanges := CompareExamples(&lDoc, &rDoc) 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, "cure all", extChanges.Changes[0].New) } @@ -87,7 +86,7 @@ x-herbs: cure all` extChanges := CompareExamples(&lDoc, &rDoc) 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, "cure all", extChanges.ExtensionChanges.Changes[0].New) } diff --git a/what-changed/model/extensions.go b/what-changed/model/extensions.go index b0d301c..7650df1 100644 --- a/what-changed/model/extensions.go +++ b/what-changed/model/extensions.go @@ -5,13 +5,12 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low" - "github.com/pb33f/libopenapi/what-changed/core" "strings" ) // ExtensionChanges represents any changes to custom extensions defined for an OpenAPI object. type ExtensionChanges struct { - core.PropertyChanges + PropertyChanges } 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 } - var changes []*core.Change + var changes []*Change 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 { - var props []*core.PropertyCheck + var props []*PropertyCheck - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: seenLeft[i].ValueNode, RightNode: seenRight[i].ValueNode, Label: i, @@ -62,12 +61,12 @@ func CompareExtensions(l, r map[low.KeyReference[string]]low.ValueReference[any] }) // check properties - core.CheckProperties(props) + CheckProperties(props) } } for i := range seenRight { if seenLeft[i] == nil { - core.CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true) + CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true) } } ex := new(ExtensionChanges) diff --git a/what-changed/model/extensions_test.go b/what-changed/model/extensions_test.go index 0b7c0d7..af98ced 100644 --- a/what-changed/model/extensions_test.go +++ b/what-changed/model/extensions_test.go @@ -5,7 +5,6 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -26,7 +25,7 @@ func TestCompareExtensions(t *testing.T) { extChanges := CompareExtensions(lExt, rExt) 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, "2", extChanges.Changes[0].New) assert.False(t, extChanges.Changes[0].Context.HasChanged()) @@ -50,7 +49,7 @@ x-test: 1` extChanges := CompareExtensions(lExt, rExt) 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, -1, extChanges.Changes[0].Context.NewLine) assert.Equal(t, "1", extChanges.Changes[0].Original) @@ -74,7 +73,7 @@ x-test: 1` extChanges := CompareExtensions(lExt, rExt) 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, 2, extChanges.Changes[0].Context.NewLine) assert.Equal(t, "1", extChanges.Changes[0].New) diff --git a/what-changed/model/external_docs.go b/what-changed/model/external_docs.go index 17b013f..ada3fb0 100644 --- a/what-changed/model/external_docs.go +++ b/what-changed/model/external_docs.go @@ -6,12 +6,11 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low/base" "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. type ExternalDocChanges struct { - core.PropertyChanges + PropertyChanges 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 // is returned, otherwise if nothing changed - then nil is returned. func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges { - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck // URL - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.URL.ValueNode, RightNode: r.URL.ValueNode, Label: v3.URLLabel, @@ -48,7 +47,7 @@ func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges { }) // description. - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Description.ValueNode, RightNode: r.Description.ValueNode, Label: v3.DescriptionLabel, @@ -59,7 +58,7 @@ func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges { }) // check everything. - core.CheckProperties(props) + CheckProperties(props) dc := new(ExternalDocChanges) dc.Changes = changes diff --git a/what-changed/model/external_docs_test.go b/what-changed/model/external_docs_test.go index ef05035..25578a5 100644 --- a/what-changed/model/external_docs_test.go +++ b/what-changed/model/external_docs_test.go @@ -7,7 +7,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" lowbase "github.com/pb33f/libopenapi/datamodel/low/base" lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -43,7 +42,7 @@ x-testing: hiya!` // validate property changes urlChange := extChanges.Changes[0] - assert.Equal(t, core.Modified, urlChange.ChangeType) + assert.Equal(t, Modified, urlChange.ChangeType) assert.False(t, urlChange.Context.HasChanged()) assert.Equal(t, "https://pb33f.io", urlChange.Original) assert.Equal(t, "https://quobix.com", urlChange.New) @@ -51,7 +50,7 @@ x-testing: hiya!` assert.Equal(t, lowv3.URLLabel, urlChange.Property) descChange := extChanges.Changes[1] - assert.Equal(t, core.Modified, descChange.ChangeType) + assert.Equal(t, Modified, descChange.ChangeType) assert.False(t, descChange.Context.HasChanged()) assert.Equal(t, "this is another test", descChange.New) assert.Equal(t, "this is a test", descChange.Original) @@ -60,7 +59,7 @@ x-testing: hiya!` // validate extensions 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.Equal(t, "hiya!", extChange.New) assert.Equal(t, "hello", extChange.Original) @@ -98,21 +97,21 @@ url: https://quobix.com` // validate property changes urlChange := extChanges.Changes[0] - assert.Equal(t, core.Modified, urlChange.ChangeType) + assert.Equal(t, Modified, urlChange.ChangeType) assert.True(t, urlChange.Context.HasChanged()) assert.Equal(t, "https://pb33f.io", urlChange.Original) assert.Equal(t, "https://quobix.com", urlChange.New) assert.Equal(t, lowv3.URLLabel, urlChange.Property) descChange := extChanges.Changes[1] - assert.Equal(t, core.Modified, descChange.ChangeType) + assert.Equal(t, Modified, descChange.ChangeType) assert.True(t, descChange.Context.HasChanged()) assert.Equal(t, "this is another test", descChange.New) assert.Equal(t, "this is a test", descChange.Original) // validate extensions 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.Equal(t, "hiya!", extChange.New) assert.Equal(t, "hello", extChange.Original) @@ -170,7 +169,7 @@ x-testing: hello` // compare. extChanges := CompareExternalDocs(&lDoc, &rDoc) 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) { @@ -195,7 +194,7 @@ url: https://pb33f.io` // compare. extChanges := CompareExternalDocs(&lDoc, &rDoc) 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) { @@ -220,7 +219,7 @@ description: something` // compare. extChanges := CompareExternalDocs(&lDoc, &rDoc) 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) { @@ -245,5 +244,5 @@ url: https://pb33f.io` // compare extChanges := CompareExternalDocs(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) - assert.Equal(t, core.PropertyRemoved, extChanges.Changes[0].ChangeType) + assert.Equal(t, PropertyRemoved, extChanges.Changes[0].ChangeType) } diff --git a/what-changed/model/header.go b/what-changed/model/header.go index 00d64c2..8e9bae8 100644 --- a/what-changed/model/header.go +++ b/what-changed/model/header.go @@ -7,12 +7,11 @@ import ( "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/what-changed/core" "reflect" ) type HeaderChanges struct { - core.PropertyChanges + PropertyChanges SchemaChanges *SchemaChanges ExamplesChanges map[string]*ExampleChanges ContentChanges map[string]*MediaTypeChanges @@ -56,8 +55,8 @@ func (h *HeaderChanges) TotalBreakingChanges() int { return c } -func addOpenAPIHeaderProperties(left, right low.IsHeader, changes *[]*core.Change) []*core.PropertyCheck { - var props []*core.PropertyCheck +func addOpenAPIHeaderProperties(left, right low.IsHeader, changes *[]*Change) []*PropertyCheck { + var props []*PropertyCheck // style addPropertyCheck(&props, left.GetStyle().ValueNode, right.GetStyle().ValueNode, @@ -90,8 +89,8 @@ func addOpenAPIHeaderProperties(left, right low.IsHeader, changes *[]*core.Chang return props } -func addSwaggerHeaderProperties(left, right low.IsHeader, changes *[]*core.Change) []*core.PropertyCheck { - var props []*core.PropertyCheck +func addSwaggerHeaderProperties(left, right low.IsHeader, changes *[]*Change) []*PropertyCheck { + var props []*PropertyCheck // type addPropertyCheck(&props, left.GetType().ValueNode, right.GetType().ValueNode, @@ -152,8 +151,8 @@ func addSwaggerHeaderProperties(left, right low.IsHeader, changes *[]*core.Chang return props } -func addCommonHeaderProperties(left, right low.IsHeader, changes *[]*core.Change) []*core.PropertyCheck { - var props []*core.PropertyCheck +func addCommonHeaderProperties(left, right low.IsHeader, changes *[]*Change) []*PropertyCheck { + var props []*PropertyCheck // description 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 { - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck hc := new(HeaderChanges) // handle swagger. if reflect.TypeOf(&v2.Header{}) == reflect.TypeOf(l) && reflect.TypeOf(&v2.Header{}) == reflect.TypeOf(r) { lHeader := l.(*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, addSwaggerHeaderProperties(lHeader, rHeader, &changes)...) // enum 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 @@ -195,11 +200,11 @@ func CompareHeaders(l, r any) *HeaderChanges { } } 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) } 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) } 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) { lHeader := l.(*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, addOpenAPIHeaderProperties(lHeader, rHeader, &changes)...) @@ -218,17 +229,17 @@ func CompareHeaders(l, r any) *HeaderChanges { } // examples - hc.ExamplesChanges = core.CheckMapForChanges(lHeader.Examples.Value, rHeader.Examples.Value, + hc.ExamplesChanges = CheckMapForChanges(lHeader.Examples.Value, rHeader.Examples.Value, &changes, v3.ExamplesLabel, CompareExamples) // content - hc.ContentChanges = core.CheckMapForChanges(lHeader.Content.Value, rHeader.Content.Value, + hc.ContentChanges = CheckMapForChanges(lHeader.Content.Value, rHeader.Content.Value, &changes, v3.ContentLabel, CompareMediaTypes) hc.ExtensionChanges = CompareExtensions(lHeader.Extensions, rHeader.Extensions) } - core.CheckProperties(props) + CheckProperties(props) hc.Changes = changes if hc.TotalChanges() <= 0 { return nil diff --git a/what-changed/model/header_test.go b/what-changed/model/header_test.go index a211a91..7291e04 100644 --- a/what-changed/model/header_test.go +++ b/what-changed/model/header_test.go @@ -7,7 +7,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -168,7 +167,7 @@ x-beer: yummy` assert.NotNil(t, extChanges) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -212,7 +211,7 @@ x-beer: yummy` assert.NotNil(t, extChanges) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { diff --git a/what-changed/model/info.go b/what-changed/model/info.go index 72b6e74..04cbc8e 100644 --- a/what-changed/model/info.go +++ b/what-changed/model/info.go @@ -6,12 +6,11 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low/base" "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 type InfoChanges struct { - core.PropertyChanges + PropertyChanges ContactChanges *ContactChanges LicenseChanges *LicenseChanges } @@ -38,11 +37,11 @@ func (i *InfoChanges) TotalBreakingChanges() int { // returned instead. func CompareInfo(l, r *base.Info) *InfoChanges { - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck // Title - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Title.ValueNode, RightNode: r.Title.ValueNode, Label: v3.TitleLabel, @@ -53,7 +52,7 @@ func CompareInfo(l, r *base.Info) *InfoChanges { }) // Description - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Description.ValueNode, RightNode: r.Description.ValueNode, Label: v3.DescriptionLabel, @@ -64,7 +63,7 @@ func CompareInfo(l, r *base.Info) *InfoChanges { }) // TermsOfService - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.TermsOfService.ValueNode, RightNode: r.TermsOfService.ValueNode, Label: v3.TermsOfServiceLabel, @@ -75,7 +74,7 @@ func CompareInfo(l, r *base.Info) *InfoChanges { }) // Version - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Version.ValueNode, RightNode: r.Version.ValueNode, Label: v3.VersionLabel, @@ -86,7 +85,7 @@ func CompareInfo(l, r *base.Info) *InfoChanges { }) // check properties - core.CheckProperties(props) + CheckProperties(props) i := new(InfoChanges) @@ -95,11 +94,11 @@ func CompareInfo(l, r *base.Info) *InfoChanges { i.ContactChanges = CompareContact(l.Contact.Value, r.Contact.Value) } else { 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) } 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) } } @@ -109,11 +108,11 @@ func CompareInfo(l, r *base.Info) *InfoChanges { i.LicenseChanges = CompareLicense(l.License.Value, r.License.Value) } else { 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) } 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) } } diff --git a/what-changed/model/info_test.go b/what-changed/model/info_test.go index cc39359..b413306 100644 --- a/what-changed/model/info_test.go +++ b/what-changed/model/info_test.go @@ -7,7 +7,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -49,7 +48,7 @@ license: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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) } @@ -89,7 +88,7 @@ license: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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) } @@ -128,7 +127,7 @@ license: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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) } @@ -165,7 +164,7 @@ contact: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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) } @@ -202,7 +201,7 @@ license: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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) } @@ -241,7 +240,7 @@ license: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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) } @@ -277,7 +276,7 @@ license: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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) } @@ -313,7 +312,7 @@ license: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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) } @@ -352,7 +351,7 @@ license: // compare. extChanges := CompareInfo(&lDoc, &rDoc) 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, 0, extChanges.TotalBreakingChanges()) } diff --git a/what-changed/model/items.go b/what-changed/model/items.go index 0fa547a..3ae1867 100644 --- a/what-changed/model/items.go +++ b/what-changed/model/items.go @@ -6,11 +6,10 @@ package model import ( v2 "github.com/pb33f/libopenapi/datamodel/low/v2" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" ) type ItemsChanges struct { - core.PropertyChanges + PropertyChanges ItemsChanges *ItemsChanges } @@ -32,14 +31,14 @@ func (i *ItemsChanges) TotalBreakingChanges() int { func CompareItems(l, r *v2.Items) *ItemsChanges { - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck ic := new(ItemsChanges) // header is identical to items, except for a description. props = append(props, addSwaggerHeaderProperties(l, r, &changes)...) - core.CheckProperties(props) + CheckProperties(props) if !l.Items.IsEmpty() && !r.Items.IsEmpty() { // 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() { // added items - core.CreateChange(&changes, core.PropertyAdded, v3.ItemsLabel, + CreateChange(&changes, PropertyAdded, v3.ItemsLabel, nil, r.Items.GetValueNode(), true, nil, r.Items.GetValue()) } if !l.Items.IsEmpty() && r.Items.IsEmpty() { // removed items - core.CreateChange(&changes, core.PropertyRemoved, v3.ItemsLabel, + CreateChange(&changes, PropertyRemoved, v3.ItemsLabel, l.Items.GetValueNode(), nil, true, l.Items.GetValue(), nil) } diff --git a/what-changed/model/items_test.go b/what-changed/model/items_test.go index a1a34c0..6b1acd8 100644 --- a/what-changed/model/items_test.go +++ b/what-changed/model/items_test.go @@ -7,7 +7,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -96,7 +95,7 @@ items: assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges()) 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) { @@ -125,7 +124,7 @@ items: assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges()) 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) { diff --git a/what-changed/model/license.go b/what-changed/model/license.go index 48cf676..d23e1b1 100644 --- a/what-changed/model/license.go +++ b/what-changed/model/license.go @@ -6,12 +6,11 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low/base" "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 type LicenseChanges struct { - core.PropertyChanges + PropertyChanges } // TotalChanges represents the total number of changes made to a License instance. @@ -29,11 +28,11 @@ func (l *LicenseChanges) TotalBreakingChanges() int { // returns nil. func CompareLicense(l, r *base.License) *LicenseChanges { - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck // check URL - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.URL.ValueNode, RightNode: r.URL.ValueNode, Label: v3.URLLabel, @@ -44,7 +43,7 @@ func CompareLicense(l, r *base.License) *LicenseChanges { }) // check name - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Name.ValueNode, RightNode: r.Name.ValueNode, Label: v3.NameLabel, @@ -55,7 +54,7 @@ func CompareLicense(l, r *base.License) *LicenseChanges { }) // check everything. - core.CheckProperties(props) + CheckProperties(props) lc := new(LicenseChanges) lc.Changes = changes diff --git a/what-changed/model/license_test.go b/what-changed/model/license_test.go index 11fb522..74eefbd 100644 --- a/what-changed/model/license_test.go +++ b/what-changed/model/license_test.go @@ -6,7 +6,6 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low" lowbase "github.com/pb33f/libopenapi/datamodel/low/base" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -34,7 +33,7 @@ url: https://pb33f.io` // compare. extChanges := CompareLicense(&lDoc, &rDoc) 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()) } @@ -61,7 +60,7 @@ url: https://pb33f.io` // compare. extChanges := CompareLicense(&lDoc, &rDoc) 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. extChanges := CompareLicense(&lDoc, &rDoc) 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. extChanges := CompareLicense(&lDoc, &rDoc) 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. extChanges := CompareLicense(&lDoc, &rDoc) 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. extChanges := CompareLicense(&lDoc, &rDoc) assert.Equal(t, 2, extChanges.TotalChanges()) - assert.Equal(t, core.Modified, extChanges.Changes[0].ChangeType) - assert.Equal(t, core.PropertyRemoved, extChanges.Changes[1].ChangeType) + assert.Equal(t, Modified, extChanges.Changes[0].ChangeType) + assert.Equal(t, PropertyRemoved, extChanges.Changes[1].ChangeType) } func TestCompareLicense_Identical(t *testing.T) { diff --git a/what-changed/model/media_type.go b/what-changed/model/media_type.go index 2f7ed17..306afa0 100644 --- a/what-changed/model/media_type.go +++ b/what-changed/model/media_type.go @@ -5,11 +5,10 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" ) type MediaTypeChanges struct { - core.PropertyChanges + PropertyChanges SchemaChanges *SchemaChanges ExtensionChanges *ExtensionChanges ExampleChanges map[string]*ExampleChanges @@ -53,8 +52,8 @@ func (m *MediaTypeChanges) TotalBreakingChanges() int { func CompareMediaTypes(l, r *v3.MediaType) *MediaTypeChanges { - var props []*core.PropertyCheck - var changes []*core.Change + var props []*PropertyCheck + var changes []*Change mc := new(MediaTypeChanges) @@ -62,27 +61,27 @@ func CompareMediaTypes(l, r *v3.MediaType) *MediaTypeChanges { addPropertyCheck(&props, l.Example.ValueNode, r.Example.ValueNode, l.Example.Value, r.Example.Value, &changes, v3.ExampleLabel, false) - core.CheckProperties(props) + CheckProperties(props) // schema if !l.Schema.IsEmpty() && !r.Schema.IsEmpty() { mc.SchemaChanges = CompareSchemas(l.Schema.Value, r.Schema.Value) } 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) } 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) } // examples - mc.ExampleChanges = core.CheckMapForChanges(l.Examples.Value, r.Examples.Value, + mc.ExampleChanges = CheckMapForChanges(l.Examples.Value, r.Examples.Value, &changes, v3.ExamplesLabel, CompareExamples) // encoding - mc.EncodingChanges = core.CheckMapForChanges(l.Encoding.Value, r.Encoding.Value, + mc.EncodingChanges = CheckMapForChanges(l.Encoding.Value, r.Encoding.Value, &changes, v3.EncodingLabel, CompareEncoding) mc.ExtensionChanges = CompareExtensions(l.Extensions, r.Extensions) diff --git a/what-changed/model/media_type_test.go b/what-changed/model/media_type_test.go index 29e17f7..41773be 100644 --- a/what-changed/model/media_type_test.go +++ b/what-changed/model/media_type_test.go @@ -6,7 +6,6 @@ package model import ( "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" "gopkg.in/yaml.v3" "testing" @@ -86,7 +85,7 @@ encoding: assert.NotNil(t, extChanges) assert.Equal(t, 1, extChanges.TotalChanges()) 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) } @@ -125,7 +124,7 @@ encoding: assert.NotNil(t, extChanges) assert.Equal(t, 1, extChanges.TotalChanges()) 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) } @@ -164,7 +163,7 @@ encoding: assert.NotNil(t, extChanges) assert.Equal(t, 1, extChanges.TotalChanges()) 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) } diff --git a/what-changed/model/parameter.go b/what-changed/model/parameter.go index 739d24f..f8d7a31 100644 --- a/what-changed/model/parameter.go +++ b/what-changed/model/parameter.go @@ -8,13 +8,12 @@ import ( "github.com/pb33f/libopenapi/datamodel/low/base" v2 "github.com/pb33f/libopenapi/datamodel/low/v2" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "gopkg.in/yaml.v3" "reflect" ) type ParameterChanges struct { - core.PropertyChanges + PropertyChanges SchemaChanges *SchemaChanges ExtensionChanges *ExtensionChanges @@ -62,9 +61,9 @@ func (p *ParameterChanges) TotalBreakingChanges() int { return c } -func addPropertyCheck(props *[]*core.PropertyCheck, - lvn, rvn *yaml.Node, lv, rv any, changes *[]*core.Change, label string, breaking bool) { - *props = append(*props, &core.PropertyCheck{ +func addPropertyCheck(props *[]*PropertyCheck, + lvn, rvn *yaml.Node, lv, rv any, changes *[]*Change, label string, breaking bool) { + *props = append(*props, &PropertyCheck{ LeftNode: lvn, RightNode: rvn, Label: label, @@ -75,8 +74,8 @@ func addPropertyCheck(props *[]*core.PropertyCheck, }) } -func addOpenAPIParameterProperties(left, right low.IsParameter, changes *[]*core.Change) []*core.PropertyCheck { - var props []*core.PropertyCheck +func addOpenAPIParameterProperties(left, right low.IsParameter, changes *[]*Change) []*PropertyCheck { + var props []*PropertyCheck // style addPropertyCheck(&props, left.GetStyle().ValueNode, right.GetStyle().ValueNode, @@ -101,8 +100,8 @@ func addOpenAPIParameterProperties(left, right low.IsParameter, changes *[]*core return props } -func addSwaggerParameterProperties(left, right low.IsParameter, changes *[]*core.Change) []*core.PropertyCheck { - var props []*core.PropertyCheck +func addSwaggerParameterProperties(left, right low.IsParameter, changes *[]*Change) []*PropertyCheck { + var props []*PropertyCheck // type addPropertyCheck(&props, left.GetType().ValueNode, right.GetType().ValueNode, @@ -167,8 +166,8 @@ func addSwaggerParameterProperties(left, right low.IsParameter, changes *[]*core return props } -func addCommonParameterProperties(left, right low.IsParameter, changes *[]*core.Change) []*core.PropertyCheck { - var props []*core.PropertyCheck +func addCommonParameterProperties(left, right low.IsParameter, changes *[]*Change) []*PropertyCheck { + var props []*PropertyCheck addPropertyCheck(&props, left.GetName().ValueNode, right.GetName().ValueNode, 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 { - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck pc := new(ParameterChanges) var lSchema *base.SchemaProxy @@ -231,19 +230,19 @@ func CompareParameters(l, r any) *ParameterChanges { } } 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, rParam.Items.Value) } 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, nil) } // enum 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) // examples - pc.ExamplesChanges = core.CheckMapForChanges(lParam.Examples.Value, rParam.Examples.Value, + pc.ExamplesChanges = CheckMapForChanges(lParam.Examples.Value, rParam.Examples.Value, &changes, v3.ExamplesLabel, CompareExamples) // content - pc.ContentChanges = core.CheckMapForChanges(lParam.Content.Value, rParam.Content.Value, + pc.ContentChanges = CheckMapForChanges(lParam.Content.Value, rParam.Content.Value, &changes, v3.ContentLabel, CompareMediaTypes) } - core.CheckProperties(props) + CheckProperties(props) if lSchema != nil && rSchema != nil { pc.SchemaChanges = CompareSchemas(lSchema, rSchema) } if lSchema != nil && rSchema == nil { - core.CreateChange(&changes, core.ObjectRemoved, v3.SchemaLabel, + CreateChange(&changes, ObjectRemoved, v3.SchemaLabel, lSchema.GetValueNode(), nil, true, lSchema, nil) } if lSchema == nil && rSchema != nil { - core.CreateChange(&changes, core.ObjectAdded, v3.SchemaLabel, + CreateChange(&changes, ObjectAdded, v3.SchemaLabel, nil, rSchema.GetValueNode(), true, nil, rSchema) } @@ -305,22 +304,22 @@ func CompareParameters(l, r any) *ParameterChanges { 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 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.GetValue(), expRight.GetValue()) } } 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.GetValue()) } if expLeft.Value != nil && expRight.Value == nil { - core.CreateChange(&changes, core.PropertyRemoved, v3.ExampleLabel, + CreateChange(&changes, PropertyRemoved, v3.ExampleLabel, expLeft.GetValueNode(), nil, false, expLeft.GetValue(), nil) diff --git a/what-changed/model/parameter_test.go b/what-changed/model/parameter_test.go index 1122ba4..f7b78dc 100644 --- a/what-changed/model/parameter_test.go +++ b/what-changed/model/parameter_test.go @@ -7,7 +7,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -107,7 +106,7 @@ schema: extChanges := CompareParameters(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) assert.Equal(t, 1, extChanges.TotalChanges()) 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) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -256,7 +255,7 @@ example: a string` extChanges := CompareParameters(&rDoc, &lDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -284,7 +283,7 @@ func TestCompareParameters_V3_ExamplesChanged(t *testing.T) { extChanges := CompareParameters(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -315,7 +314,7 @@ func TestCompareParameters_V3_ExamplesAdded(t *testing.T) { extChanges := CompareParameters(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -346,7 +345,7 @@ func TestCompareParameters_V3_ExamplesRemoved(t *testing.T) { extChanges := CompareParameters(&rDoc, &lDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -377,7 +376,7 @@ func TestCompareParameters_V3_ContentChanged(t *testing.T) { extChanges := CompareParameters(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) assert.Equal(t, 0, extChanges.TotalBreakingChanges()) - assert.Equal(t, core.Modified, + assert.Equal(t, Modified, extChanges.ContentChanges["application/json"].SchemaChanges.Changes[0].ChangeType) } @@ -412,7 +411,7 @@ func TestCompareParameters_V3_ContentAdded(t *testing.T) { extChanges := CompareParameters(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -511,7 +510,7 @@ example: a string` extChanges := CompareParameters(&rDoc, &lDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -581,7 +580,7 @@ func TestCompareParameters_V2_ItemsChange(t *testing.T) { extChanges := CompareParameters(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { @@ -634,7 +633,7 @@ items: extChanges := CompareParameters(&rDoc, &lDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) { diff --git a/what-changed/model/schema.go b/what-changed/model/schema.go index b58c283..838fe74 100644 --- a/what-changed/model/schema.go +++ b/what-changed/model/schema.go @@ -8,7 +8,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/base" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "gopkg.in/yaml.v3" "sort" "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 // PropertyChanges.Changes, and not in the AnyOfChanges property. type SchemaChanges struct { - core.PropertyChanges + PropertyChanges DiscriminatorChanges *DiscriminatorChanges AllOfChanges []*SchemaChanges AnyOfChanges []*SchemaChanges @@ -131,18 +130,18 @@ func (s *SchemaChanges) TotalBreakingChanges() int { func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges { sc := new(SchemaChanges) - var changes []*core.Change + var changes []*Change // Added if l == nil && r != nil { - core.CreateChange(&changes, core.ObjectAdded, v3.SchemaLabel, + CreateChange(&changes, ObjectAdded, v3.SchemaLabel, nil, nil, true, nil, r) sc.Changes = changes } // Removed if l != nil && r == nil { - core.CreateChange(&changes, core.ObjectRemoved, v3.SchemaLabel, + CreateChange(&changes, ObjectRemoved, v3.SchemaLabel, nil, nil, true, l, nil) sc.Changes = changes } @@ -157,7 +156,7 @@ func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges { return nil } else { // 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(), r.GetSchemaReference()) sc.Changes = changes @@ -167,7 +166,7 @@ func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges { // changed from inline to ref 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()) sc.Changes = changes return sc // we're done here @@ -175,7 +174,7 @@ func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges { // changed from ref to inline 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) sc.Changes = changes return sc // done, nothing else to do. @@ -235,15 +234,15 @@ func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges { 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 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) } // XML added 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()) } @@ -258,7 +257,7 @@ func checkSchemaXML(lSchema *base.Schema, rSchema *base.Schema, changes *[]*core func checkPropertiesPropertyOfASchema( lSchema *base.Schema, rSchema *base.Schema, - changes *[]*core.Change, + changes *[]*Change, sc *SchemaChanges, doneChan chan bool) int { @@ -319,10 +318,10 @@ func checkPropertiesPropertyOfASchema( if lProps[w] != rProps[w] { // 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]]) - core.CreateChange(changes, core.ObjectRemoved, v3.PropertiesLabel, + CreateChange(changes, ObjectRemoved, v3.PropertiesLabel, 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) } 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) } } @@ -351,7 +350,7 @@ func checkPropertiesPropertyOfASchema( go checkProperty(rProps[w], lEntities[lProps[w]], rEntities[rProps[w]], propChanges, doneChan) } 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]]) } } @@ -363,12 +362,12 @@ func checkPropertiesPropertyOfASchema( func checkSchemaPropertyChanges( lSchema *base.Schema, rSchema *base.Schema, - changes *[]*core.Change, sc *SchemaChanges) { + changes *[]*Change, sc *SchemaChanges) { - var props []*core.PropertyCheck + var props []*PropertyCheck // $schema (breaking change) - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.SchemaTypeRef.ValueNode, RightNode: rSchema.SchemaTypeRef.ValueNode, Label: v3.SchemaDialectLabel, @@ -379,7 +378,7 @@ func checkSchemaPropertyChanges( }) // ExclusiveMaximum - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.ExclusiveMaximum.ValueNode, RightNode: rSchema.ExclusiveMaximum.ValueNode, Label: v3.ExclusiveMaximumLabel, @@ -390,7 +389,7 @@ func checkSchemaPropertyChanges( }) // ExclusiveMinimum - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.ExclusiveMinimum.ValueNode, RightNode: rSchema.ExclusiveMinimum.ValueNode, Label: v3.ExclusiveMinimumLabel, @@ -401,7 +400,7 @@ func checkSchemaPropertyChanges( }) // Type - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Type.ValueNode, RightNode: rSchema.Type.ValueNode, Label: v3.TypeLabel, @@ -412,7 +411,7 @@ func checkSchemaPropertyChanges( }) // Title - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Title.ValueNode, RightNode: rSchema.Title.ValueNode, Label: v3.TitleLabel, @@ -423,7 +422,7 @@ func checkSchemaPropertyChanges( }) // MultipleOf - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.MultipleOf.ValueNode, RightNode: rSchema.MultipleOf.ValueNode, Label: v3.MultipleOfLabel, @@ -434,7 +433,7 @@ func checkSchemaPropertyChanges( }) // Maximum - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Maximum.ValueNode, RightNode: rSchema.Maximum.ValueNode, Label: v3.MaximumLabel, @@ -445,7 +444,7 @@ func checkSchemaPropertyChanges( }) // Minimum - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Minimum.ValueNode, RightNode: rSchema.Minimum.ValueNode, Label: v3.MinimumLabel, @@ -456,7 +455,7 @@ func checkSchemaPropertyChanges( }) // MaxLength - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.MaxLength.ValueNode, RightNode: rSchema.MaxLength.ValueNode, Label: v3.MaxLengthLabel, @@ -467,7 +466,7 @@ func checkSchemaPropertyChanges( }) // MinLength - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.MinLength.ValueNode, RightNode: rSchema.MinLength.ValueNode, Label: v3.MinLengthLabel, @@ -478,7 +477,7 @@ func checkSchemaPropertyChanges( }) // Pattern - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Pattern.ValueNode, RightNode: rSchema.Pattern.ValueNode, Label: v3.PatternLabel, @@ -489,7 +488,7 @@ func checkSchemaPropertyChanges( }) // Format - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Format.ValueNode, RightNode: rSchema.Format.ValueNode, Label: v3.FormatLabel, @@ -500,7 +499,7 @@ func checkSchemaPropertyChanges( }) // MaxItems - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.MaxItems.ValueNode, RightNode: rSchema.MaxItems.ValueNode, Label: v3.MaxItemsLabel, @@ -511,7 +510,7 @@ func checkSchemaPropertyChanges( }) // MinItems - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.MinItems.ValueNode, RightNode: rSchema.MinItems.ValueNode, Label: v3.MinItemsLabel, @@ -522,7 +521,7 @@ func checkSchemaPropertyChanges( }) // MaxProperties - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.MaxProperties.ValueNode, RightNode: rSchema.MaxProperties.ValueNode, Label: v3.MaxPropertiesLabel, @@ -533,7 +532,7 @@ func checkSchemaPropertyChanges( }) // MinProperties - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.MinProperties.ValueNode, RightNode: rSchema.MinProperties.ValueNode, Label: v3.MinPropertiesLabel, @@ -544,7 +543,7 @@ func checkSchemaPropertyChanges( }) // UniqueItems - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.UniqueItems.ValueNode, RightNode: rSchema.UniqueItems.ValueNode, Label: v3.UniqueItemsLabel, @@ -555,7 +554,7 @@ func checkSchemaPropertyChanges( }) // AdditionalProperties - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.AdditionalProperties.ValueNode, RightNode: rSchema.AdditionalProperties.ValueNode, Label: v3.AdditionalPropertiesLabel, @@ -566,7 +565,7 @@ func checkSchemaPropertyChanges( }) // Description - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Description.ValueNode, RightNode: rSchema.Description.ValueNode, Label: v3.DescriptionLabel, @@ -577,7 +576,7 @@ func checkSchemaPropertyChanges( }) // ContentEncoding - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.ContentEncoding.ValueNode, RightNode: rSchema.ContentEncoding.ValueNode, Label: v3.ContentEncodingLabel, @@ -588,7 +587,7 @@ func checkSchemaPropertyChanges( }) // ContentMediaType - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.ContentMediaType.ValueNode, RightNode: rSchema.ContentMediaType.ValueNode, Label: v3.ContentMediaType, @@ -599,7 +598,7 @@ func checkSchemaPropertyChanges( }) // Default - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Default.ValueNode, RightNode: rSchema.Default.ValueNode, Label: v3.DefaultLabel, @@ -610,7 +609,7 @@ func checkSchemaPropertyChanges( }) // Nullable - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Nullable.ValueNode, RightNode: rSchema.Nullable.ValueNode, Label: v3.NullableLabel, @@ -621,7 +620,7 @@ func checkSchemaPropertyChanges( }) // ReadOnly - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.ReadOnly.ValueNode, RightNode: rSchema.ReadOnly.ValueNode, Label: v3.ReadOnlyLabel, @@ -632,7 +631,7 @@ func checkSchemaPropertyChanges( }) // WriteOnly - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.WriteOnly.ValueNode, RightNode: rSchema.WriteOnly.ValueNode, Label: v3.WriteOnlyLabel, @@ -643,7 +642,7 @@ func checkSchemaPropertyChanges( }) // Example - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Example.ValueNode, RightNode: rSchema.Example.ValueNode, Label: v3.ExampleLabel, @@ -654,7 +653,7 @@ func checkSchemaPropertyChanges( }) // Deprecated - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: lSchema.Deprecated.ValueNode, RightNode: rSchema.Deprecated.ValueNode, Label: v3.DeprecatedLabel, @@ -675,14 +674,14 @@ func checkSchemaPropertyChanges( } for g := range k { 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, rSchema.Required.Value[k[g]].GetValue) } } for g := range j { 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, nil) } @@ -699,14 +698,14 @@ func checkSchemaPropertyChanges( } for g := range k { 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, rSchema.Enum.Value[k[g]].GetValue) } } for g := range j { 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, nil) } @@ -721,12 +720,12 @@ func checkSchemaPropertyChanges( } // added Discriminator 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) } // removed Discriminator 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) } @@ -739,12 +738,12 @@ func checkSchemaPropertyChanges( } // added ExternalDocs 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) } // removed ExternalDocs 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) } @@ -752,10 +751,10 @@ func checkSchemaPropertyChanges( sc.ExtensionChanges = CompareExtensions(lSchema.Extensions, rSchema.Extensions) // 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+) var lExampKey, rExampKey []string 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) { for i := range lExampKey { if lExampKey[i] != rExampKey[i] { - core.CreateChange(changes, core.Modified, v3.ExamplesLabel, + CreateChange(changes, Modified, v3.ExamplesLabel, lExampN[lExampKey[i]], rExampN[rExampKey[i]], false, 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) { for i := range lExampKey { 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, lExampVal[lExampKey[i]], rExampVal[rExampKey[i]]) } if i >= len(rExampKey) { - core.CreateChange(changes, core.ObjectRemoved, v3.ExamplesLabel, + CreateChange(changes, ObjectRemoved, v3.ExamplesLabel, lExampN[lExampKey[i]], nil, false, lExampVal[lExampKey[i]], nil) } @@ -812,12 +811,12 @@ func checkExamples(lSchema *base.Schema, rSchema *base.Schema, changes *[]*core. if len(lExampKey) < len(rExampKey) { for i := range rExampKey { 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, lExampVal[lExampKey[i]], rExampVal[rExampKey[i]]) } if i >= len(lExampKey) { - core.CreateChange(changes, core.ObjectAdded, v3.ExamplesLabel, + CreateChange(changes, ObjectAdded, v3.ExamplesLabel, nil, rExampN[rExampKey[i]], false, nil, rExampVal[rExampKey[i]]) } @@ -830,7 +829,7 @@ func extractSchemaChanges( rSchema []low.ValueReference[*base.SchemaProxy], label string, sc *[]*SchemaChanges, - changes *[]*core.Change, + changes *[]*Change, done chan bool) { // 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]])) } if w >= len(rKeys) { - core.CreateChange(changes, core.ObjectRemoved, label, + CreateChange(changes, ObjectRemoved, label, 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]])) } if w >= len(lKeys) { - core.CreateChange(changes, core.ObjectAdded, label, + CreateChange(changes, ObjectAdded, label, nil, rEntities[rKeys[w]].GetValueNode(), false, nil, rEntities[rKeys[w]]) } } diff --git a/what-changed/model/schema_test.go b/what-changed/model/schema_test.go index c8f2508..6bc6300 100644 --- a/what-changed/model/schema_test.go +++ b/what-changed/model/schema_test.go @@ -10,7 +10,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low/base" v2 "github.com/pb33f/libopenapi/datamodel/low/v2" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "testing" ) @@ -43,7 +42,7 @@ func TestCompareSchemas_PropertyModification(t *testing.T) { assert.NotNil(t, changes) assert.Equal(t, 1, changes.TotalChanges()) 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) } @@ -68,7 +67,7 @@ func TestCompareSchemas_PropertyAdd(t *testing.T) { changes := CompareSchemas(lSchemaProxy, rSchemaProxy) assert.NotNil(t, changes) 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, v3.DescriptionLabel, changes.Changes[0].Property) } @@ -94,7 +93,7 @@ func TestCompareSchemas_PropertyRemove(t *testing.T) { changes := CompareSchemas(lSchemaProxy, rSchemaProxy) assert.NotNil(t, changes) 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, v3.DescriptionLabel, changes.Changes[0].Property) } @@ -118,7 +117,7 @@ func TestCompareSchemas_Removed(t *testing.T) { changes := CompareSchemas(lSchemaProxy, rSchemaProxy) assert.NotNil(t, changes) 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) { @@ -140,7 +139,7 @@ func TestCompareSchemas_Added(t *testing.T) { changes := CompareSchemas(rSchemaProxy, lSchemaProxy) assert.NotNil(t, changes) 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) { @@ -221,7 +220,7 @@ func TestCompareSchemas_RefChanged(t *testing.T) { changes := CompareSchemas(lSchemaProxy, rSchemaProxy) assert.NotNil(t, changes) 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) } @@ -249,7 +248,7 @@ func TestCompareSchemas_RefToInline(t *testing.T) { changes := CompareSchemas(lSchemaProxy, rSchemaProxy) assert.NotNil(t, changes) 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, "#/components/schemas/No", changes.Changes[0].Original) @@ -279,7 +278,7 @@ func TestCompareSchemas_InlineToRef(t *testing.T) { changes := CompareSchemas(rSchemaProxy, lSchemaProxy) assert.NotNil(t, changes) 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, "#/components/schemas/No", changes.Changes[0].New) @@ -337,7 +336,7 @@ func TestCompareSchemas_RequiredAdded(t *testing.T) { changes := CompareSchemas(lSchemaProxy, rSchemaProxy) assert.NotNil(t, changes) 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, v3.RequiredLabel, changes.Changes[0].Property) } @@ -365,7 +364,7 @@ func TestCompareSchemas_RequiredRemoved(t *testing.T) { changes := CompareSchemas(rSchemaProxy, lSchemaProxy) assert.NotNil(t, changes) 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, v3.RequiredLabel, changes.Changes[0].Property) } @@ -390,7 +389,7 @@ func TestCompareSchemas_EnumAdded(t *testing.T) { changes := CompareSchemas(lSchemaProxy, rSchemaProxy) assert.NotNil(t, changes) 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, v3.EnumLabel, changes.Changes[0].Property) } @@ -415,7 +414,7 @@ func TestCompareSchemas_EnumRemoved(t *testing.T) { changes := CompareSchemas(rSchemaProxy, lSchemaProxy) assert.NotNil(t, changes) 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, v3.EnumLabel, changes.Changes[0].Property) } @@ -446,7 +445,7 @@ func TestCompareSchemas_PropertyAdded(t *testing.T) { changes := CompareSchemas(lSchemaProxy, rSchemaProxy) assert.NotNil(t, changes) 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, v3.PropertiesLabel, changes.Changes[0].Property) } @@ -477,7 +476,7 @@ func TestCompareSchemas_PropertyRemoved(t *testing.T) { changes := CompareSchemas(rSchemaProxy, lSchemaProxy) assert.NotNil(t, changes) 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, v3.PropertiesLabel, changes.Changes[0].Property) } @@ -507,7 +506,7 @@ func TestCompareSchemas_PropertyChanged(t *testing.T) { assert.NotNil(t, changes) assert.Equal(t, 1, changes.TotalChanges()) 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, "int", changes.SchemaPropertyChanges["propA"].Changes[0].Original) } @@ -537,10 +536,10 @@ func TestCompareSchemas_PropertySwap(t *testing.T) { assert.NotNil(t, changes) assert.Equal(t, 2, changes.TotalChanges()) 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, 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, v3.PropertiesLabel, changes.Changes[1].Property) } @@ -569,9 +568,9 @@ func TestCompareSchemas_AnyOfModifyAndAddItem(t *testing.T) { assert.NotNil(t, changes) assert.Equal(t, 2, changes.TotalChanges()) 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, 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, "bool", changes.AnyOfChanges[0].Changes[0].Original) } @@ -600,9 +599,9 @@ func TestCompareSchemas_AnyOfModifyAndRemoveItem(t *testing.T) { assert.NotNil(t, changes) assert.Equal(t, 2, changes.TotalChanges()) 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, 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, "string", changes.AnyOfChanges[0].Changes[0].Original) } @@ -630,7 +629,7 @@ func TestCompareSchemas_AnyOfModified(t *testing.T) { assert.NotNil(t, changes) assert.Equal(t, 1, changes.TotalChanges()) 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, "bool", changes.AnyOfChanges[0].Changes[0].Original) @@ -660,9 +659,9 @@ func TestCompareSchemas_OneOfModifyAndAddItem(t *testing.T) { assert.NotNil(t, changes) assert.Equal(t, 2, changes.TotalChanges()) 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, 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, "bool", changes.OneOfChanges[0].Changes[0].Original) } @@ -691,9 +690,9 @@ func TestCompareSchemas_AllOfModifyAndAddItem(t *testing.T) { assert.NotNil(t, changes) assert.Equal(t, 2, changes.TotalChanges()) 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, 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, "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.TotalBreakingChanges()) 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, "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.TotalBreakingChanges()) 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, "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.TotalBreakingChanges()) 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, "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.TotalBreakingChanges()) 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, "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.TotalBreakingChanges()) 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", 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.TotalBreakingChanges()) 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", 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, 0, changes.TotalBreakingChanges()) 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", changes.ExternalDocChanges.Changes[0].Original) } @@ -937,7 +936,7 @@ func TestCompareSchemas_ExternalDocsAdd(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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", 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, 0, changes.TotalBreakingChanges()) 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", 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, 0, changes.TotalBreakingChanges()) 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) } @@ -1022,7 +1021,7 @@ func TestCompareSchemas_ExampleChange(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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, "sausages", changes.Changes[0].Original) } @@ -1050,7 +1049,7 @@ func TestCompareSchemas_ExampleAdd(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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) } @@ -1077,7 +1076,7 @@ func TestCompareSchemas_ExampleRemove(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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) } @@ -1107,7 +1106,7 @@ func TestCompareSchemas_ExamplesChange(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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, "sausages", changes.Changes[0].Original) } @@ -1136,7 +1135,7 @@ func TestCompareSchemas_ExamplesAdd(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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) } @@ -1167,10 +1166,10 @@ func TestCompareSchemas_ExamplesAddAndModify(t *testing.T) { assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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, "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) } @@ -1198,7 +1197,7 @@ func TestCompareSchemas_ExamplesRemove(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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) } @@ -1229,10 +1228,10 @@ func TestCompareSchemas_ExamplesRemoveAndModify(t *testing.T) { assert.Equal(t, 2, changes.TotalChanges()) assert.Equal(t, 0, changes.TotalBreakingChanges()) 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, "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) } @@ -1260,7 +1259,7 @@ func TestCompareSchemas_XMLChange(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges()) 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, "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, 0, changes.TotalBreakingChanges()) 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) } @@ -1315,6 +1314,6 @@ func TestCompareSchemas_XMLRemove(t *testing.T) { assert.Equal(t, 1, changes.TotalChanges()) assert.Equal(t, 1, changes.TotalBreakingChanges()) 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) } diff --git a/what-changed/model/security_requirement.go b/what-changed/model/security_requirement.go index 6bd46a7..cfa6a27 100644 --- a/what-changed/model/security_requirement.go +++ b/what-changed/model/security_requirement.go @@ -7,12 +7,11 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/v2" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "gopkg.in/yaml.v3" ) type SecurityRequirementChanges struct { - core.PropertyChanges + PropertyChanges } func (s *SecurityRequirementChanges) TotalChanges() int { @@ -27,7 +26,7 @@ func CompareSecurityRequirement(l, r *v2.SecurityRequirement) *SecurityRequireme if low.AreEqual(l, r) { return nil } - var changes []*core.Change + var changes []*Change lKeys := make([]string, len(l.Values.Value)) rKeys := make([]string, len(r.Values.Value)) lValues := make(map[string]low.ValueReference[[]low.ValueReference[string]]) @@ -44,12 +43,12 @@ func CompareSecurityRequirement(l, r *v2.SecurityRequirement) *SecurityRequireme z++ } 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) } 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) } diff --git a/what-changed/model/security_requirement_test.go b/what-changed/model/security_requirement_test.go index 1734be0..7305130 100644 --- a/what-changed/model/security_requirement_test.go +++ b/what-changed/model/security_requirement_test.go @@ -6,7 +6,6 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/v2" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -71,7 +70,7 @@ biscuit: extChanges := CompareSecurityRequirement(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) } @@ -135,10 +134,10 @@ milk: extChanges := CompareSecurityRequirement(&lDoc, &rDoc) assert.Equal(t, 4, extChanges.TotalChanges()) assert.Equal(t, 2, extChanges.TotalBreakingChanges()) - assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) - assert.Equal(t, core.ObjectRemoved, extChanges.Changes[1].ChangeType) - assert.Equal(t, core.ObjectAdded, extChanges.Changes[2].ChangeType) - assert.Equal(t, core.ObjectAdded, extChanges.Changes[3].ChangeType) + assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType) + assert.Equal(t, ObjectRemoved, extChanges.Changes[1].ChangeType) + assert.Equal(t, ObjectAdded, extChanges.Changes[2].ChangeType) + assert.Equal(t, ObjectAdded, extChanges.Changes[3].ChangeType) } func TestCompareSecurityRequirement_SwapLeft(t *testing.T) { @@ -171,8 +170,8 @@ milk: extChanges := CompareSecurityRequirement(&lDoc, &rDoc) assert.Equal(t, 2, extChanges.TotalChanges()) assert.Equal(t, 1, extChanges.TotalBreakingChanges()) - assert.Equal(t, core.ObjectRemoved, extChanges.Changes[0].ChangeType) - assert.Equal(t, core.ObjectAdded, extChanges.Changes[1].ChangeType) + assert.Equal(t, ObjectRemoved, extChanges.Changes[0].ChangeType) + assert.Equal(t, ObjectAdded, extChanges.Changes[1].ChangeType) } func TestCompareSecurityRequirement_AddedRole(t *testing.T) { @@ -206,7 +205,7 @@ biscuit: extChanges := CompareSecurityRequirement(&lDoc, &rDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) } @@ -244,7 +243,7 @@ biscuit: extChanges := CompareSecurityRequirement(&lDoc, &rDoc) assert.Equal(t, 2, extChanges.TotalChanges()) 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) { @@ -344,6 +343,6 @@ biscuit: extChanges := CompareSecurityRequirement(&rDoc, &lDoc) assert.Equal(t, 1, extChanges.TotalChanges()) 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) } diff --git a/what-changed/model/tags.go b/what-changed/model/tags.go index b42f569..5d2f7ed 100644 --- a/what-changed/model/tags.go +++ b/what-changed/model/tags.go @@ -7,13 +7,12 @@ import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/base" "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "strings" ) // TagChanges represents changes made to the Tags object of an OpenAPI document. type TagChanges struct { - core.PropertyChanges + PropertyChanges ExternalDocs *ExternalDocChanges ExtensionChanges *ExtensionChanges } @@ -53,20 +52,20 @@ func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges { seenRight[strings.ToLower(r[i].Value.Name.Value)] = &h } - var changes []*core.Change + var changes []*Change // check for removals, modifications and moves 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 seenRight[i] != nil { - var props []*core.PropertyCheck + var props []*PropertyCheck // Name - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: seenLeft[i].Value.Name.ValueNode, RightNode: seenRight[i].Value.Name.ValueNode, Label: v3.NameLabel, @@ -77,7 +76,7 @@ func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges { }) // Description - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: seenLeft[i].Value.Description.ValueNode, RightNode: seenRight[i].Value.Description.ValueNode, Label: v3.DescriptionLabel, @@ -88,7 +87,7 @@ func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges { }) // check properties - core.CheckProperties(props) + CheckProperties(props) // compare external docs 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 { 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()) } } diff --git a/what-changed/model/tags_test.go b/what-changed/model/tags_test.go index ee1c852..9da63ae 100644 --- a/what-changed/model/tags_test.go +++ b/what-changed/model/tags_test.go @@ -6,7 +6,6 @@ package model import ( "github.com/pb33f/libopenapi/datamodel" lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "testing" ) @@ -49,7 +48,7 @@ tags: descChange := changes.Changes[0] assert.Equal(t, "a lovelier tag description", descChange.New) 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()) } @@ -89,7 +88,7 @@ tags: assert.Equal(t, 1, changes.TotalChanges()) descChange := changes.Changes[0] - assert.Equal(t, core.ObjectAdded, descChange.ChangeType) + assert.Equal(t, ObjectAdded, descChange.ChangeType) } func TestCompareTags_AddDeleteTag(t *testing.T) { @@ -121,8 +120,8 @@ tags: assert.Len(t, changes.Changes, 2) assert.Equal(t, 2, changes.TotalChanges()) - assert.Equal(t, core.ObjectRemoved, changes.Changes[0].ChangeType) - assert.Equal(t, core.ObjectAdded, changes.Changes[1].ChangeType) + assert.Equal(t, ObjectRemoved, changes.Changes[0].ChangeType) + assert.Equal(t, ObjectAdded, changes.Changes[1].ChangeType) assert.Equal(t, 1, changes.TotalBreakingChanges()) } @@ -227,7 +226,7 @@ tags: assert.Equal(t, 1, changes.TotalChanges()) 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 different tag description", descChange.New) assert.True(t, descChange.Context.HasChanged()) diff --git a/what-changed/model/xml.go b/what-changed/model/xml.go index b4ef74c..f6fc668 100644 --- a/what-changed/model/xml.go +++ b/what-changed/model/xml.go @@ -6,12 +6,11 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low/base" 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. type XMLChanges struct { - core.PropertyChanges + PropertyChanges ExtensionChanges *ExtensionChanges } @@ -34,11 +33,11 @@ func (x *XMLChanges) TotalBreakingChanges() int { // otherwise, if nothing changed - it will return nil func CompareXML(l, r *base.XML) *XMLChanges { xc := new(XMLChanges) - var changes []*core.Change - var props []*core.PropertyCheck + var changes []*Change + var props []*PropertyCheck // Name (breaking change) - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Name.ValueNode, RightNode: r.Name.ValueNode, Label: v3.NameLabel, @@ -49,7 +48,7 @@ func CompareXML(l, r *base.XML) *XMLChanges { }) // Namespace (breaking change) - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Namespace.ValueNode, RightNode: r.Namespace.ValueNode, Label: v3.NamespaceLabel, @@ -60,7 +59,7 @@ func CompareXML(l, r *base.XML) *XMLChanges { }) // Prefix (breaking change) - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Prefix.ValueNode, RightNode: r.Prefix.ValueNode, Label: v3.PrefixLabel, @@ -71,7 +70,7 @@ func CompareXML(l, r *base.XML) *XMLChanges { }) // Attribute (breaking change) - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Attribute.ValueNode, RightNode: r.Attribute.ValueNode, Label: v3.AttributeLabel, @@ -82,7 +81,7 @@ func CompareXML(l, r *base.XML) *XMLChanges { }) // Wrapped (breaking change) - props = append(props, &core.PropertyCheck{ + props = append(props, &PropertyCheck{ LeftNode: l.Wrapped.ValueNode, RightNode: r.Wrapped.ValueNode, Label: v3.WrappedLabel, @@ -93,7 +92,7 @@ func CompareXML(l, r *base.XML) *XMLChanges { }) // check properties - core.CheckProperties(props) + CheckProperties(props) // check extensions xc.ExtensionChanges = CheckExtensions(l, r) diff --git a/what-changed/model/xml_test.go b/what-changed/model/xml_test.go index 3c80afb..db7ca6e 100644 --- a/what-changed/model/xml_test.go +++ b/what-changed/model/xml_test.go @@ -6,7 +6,6 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low/base" - "github.com/pb33f/libopenapi/what-changed/core" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "testing" @@ -41,7 +40,7 @@ wrapped: true` // compare. extChanges := CompareXML(&lDoc, &rDoc) 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. extChanges := CompareXML(&lDoc, &rDoc) 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()) } @@ -108,7 +107,7 @@ x-coffee: time` // compare. extChanges := CompareXML(&lDoc, &rDoc) 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) }