diff --git a/datamodel/low/base/example.go b/datamodel/low/base/example.go index dd52544..b353ae3 100644 --- a/datamodel/low/base/example.go +++ b/datamodel/low/base/example.go @@ -66,6 +66,11 @@ func (ex *Example) Build(root *yaml.Node, idx *index.SpecIndex) error { return nil } +// GetExtensions will return Example extensions to satisfy the HasExtensions interface. +func (ex *Example) GetExtensions() map[low.KeyReference[string]]low.ValueReference[any] { + return ex.Extensions +} + // ExtractExampleValue will extract a primitive example value (if possible), or just the raw Value property if not. func ExtractExampleValue(exp *yaml.Node) any { if utils.IsNodeBoolValue(exp) { diff --git a/datamodel/low/v3/constants.go b/datamodel/low/v3/constants.go index 6daf7ce..ee4fefb 100644 --- a/datamodel/low/v3/constants.go +++ b/datamodel/low/v3/constants.go @@ -52,4 +52,7 @@ const ( AttributeLabel = "attribute" WrappedLabel = "wrapped" PropertyNameLabel = "propertyName" + SummaryLabel = "summary" + ValueLabel = "value" + ExternalValue = "externalValue" ) diff --git a/what-changed/contact.go b/what-changed/contact.go index c9021ab..15008f0 100644 --- a/what-changed/contact.go +++ b/what-changed/contact.go @@ -15,7 +15,7 @@ type ContactChanges struct { // TotalChanges represents the total number of changes that have occurred to a Contact object func (c *ContactChanges) TotalChanges() int { - return len(c.Changes) + return c.PropertyChanges.TotalChanges() } // TotalBreakingChanges always returns 0 for Contact objects, they are non-binding. @@ -69,7 +69,7 @@ func CompareContact(l, r *base.Contact) *ContactChanges { dc := new(ContactChanges) dc.Changes = changes - if len(changes) <= 0 { + if dc.TotalChanges() <= 0 { return nil } return dc diff --git a/what-changed/discriminator.go b/what-changed/discriminator.go index 3d09053..2d2db5e 100644 --- a/what-changed/discriminator.go +++ b/what-changed/discriminator.go @@ -76,11 +76,11 @@ func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges { } } - if len(changes) <= 0 && len(mapping) <= 0 { - return nil - } dc.Changes = changes dc.MappingChanges = mapping + if dc.TotalChanges() <= 0 { + return nil + } return dc } diff --git a/what-changed/extensions.go b/what-changed/extensions.go index 4dcc92a..89c10f3 100644 --- a/what-changed/extensions.go +++ b/what-changed/extensions.go @@ -14,7 +14,7 @@ type ExtensionChanges struct { } func (e *ExtensionChanges) TotalChanges() int { - return len(e.Changes) + return e.PropertyChanges.TotalChanges() } // TotalBreakingChanges always returns 0 for Extension objects, they are non-binding. @@ -69,10 +69,10 @@ func CompareExtensions(l, r map[low.KeyReference[string]]low.ValueReference[any] CheckForObjectAdditionOrRemoval[any](seenLeft, seenRight, i, &changes, false, true) } } - if len(changes) <= 0 { - return nil - } ex := new(ExtensionChanges) ex.Changes = changes + if ex.TotalChanges() <= 0 { + return nil + } return ex } diff --git a/what-changed/extensions_test.go b/what-changed/extensions_test.go index 017a3db..df096e9 100644 --- a/what-changed/extensions_test.go +++ b/what-changed/extensions_test.go @@ -24,7 +24,7 @@ func TestCompareExtensions(t *testing.T) { extChanges := CompareExtensions(lExt, rExt) - assert.Len(t, extChanges.TotalChanges(), 1) + assert.Equal(t, extChanges.TotalChanges(), 1) assert.Equal(t, Modified, extChanges.Changes[0].ChangeType) assert.Equal(t, "1", extChanges.Changes[0].Original) assert.Equal(t, "2", extChanges.Changes[0].New) diff --git a/what-changed/external_docs.go b/what-changed/external_docs.go index 2ceb2ec..7b90c09 100644 --- a/what-changed/external_docs.go +++ b/what-changed/external_docs.go @@ -16,9 +16,9 @@ type ExternalDocChanges struct { // TotalChanges returns a count of everything that changed func (e *ExternalDocChanges) TotalChanges() int { - c := len(e.Changes) + c := e.PropertyChanges.TotalChanges() if e.ExtensionChanges != nil { - c += len(e.ExtensionChanges.Changes) + c += e.ExtensionChanges.TotalChanges() } return c } @@ -65,7 +65,7 @@ func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges { // check extensions dc.ExtensionChanges = CheckExtensions(l, r) - if len(dc.Changes) <= 0 && dc.ExtensionChanges == nil { + if dc.TotalChanges() <= 0 { return nil } return dc diff --git a/what-changed/info.go b/what-changed/info.go index 749da17..c4a966c 100644 --- a/what-changed/info.go +++ b/what-changed/info.go @@ -17,7 +17,7 @@ type InfoChanges struct { // TotalChanges represents the total number of changes made to an Info object. func (i *InfoChanges) TotalChanges() int { - t := len(i.Changes) + t := i.PropertyChanges.TotalChanges() if i.ContactChanges != nil { t += i.ContactChanges.TotalChanges() } @@ -32,6 +32,9 @@ func (i *InfoChanges) TotalBreakingChanges() int { return 0 } +// CompareInfo will compare a left (original) and a right (new) Info object. Any changes +// will be returned in a pointer to InfoChanges, otherwise if nothing is found, then nil is +// returned instead. func CompareInfo(l, r *base.Info) *InfoChanges { var changes []*Change[*base.Info] @@ -113,9 +116,9 @@ func CompareInfo(l, r *base.Info) *InfoChanges { l.License.ValueNode, nil, false, r.License.Value, nil) } } - if len(changes) <= 0 && i.ContactChanges == nil && i.LicenseChanges == nil { + i.Changes = changes + if i.TotalChanges() <= 0 { return nil } - i.Changes = changes return i } diff --git a/what-changed/license.go b/what-changed/license.go index 4b6c20e..ec16249 100644 --- a/what-changed/license.go +++ b/what-changed/license.go @@ -15,7 +15,7 @@ type LicenseChanges struct { // TotalChanges represents the total number of changes made to a License instance. func (l *LicenseChanges) TotalChanges() int { - return len(l.Changes) + return l.PropertyChanges.TotalChanges() } // TotalBreakingChanges always returns 0 for License objects, they are non-binding. @@ -58,7 +58,7 @@ func CompareLicense(l, r *base.License) *LicenseChanges { lc := new(LicenseChanges) lc.Changes = changes - if len(changes) <= 0 { + if lc.TotalChanges() <= 0 { return nil } return lc diff --git a/what-changed/tags.go b/what-changed/tags.go index a2f0d4f..3644057 100644 --- a/what-changed/tags.go +++ b/what-changed/tags.go @@ -19,12 +19,12 @@ type TagChanges struct { // TotalChanges returns a count of everything that changed within tags. func (t *TagChanges) TotalChanges() int { - c := len(t.Changes) + c := t.PropertyChanges.TotalChanges() if t.ExternalDocs != nil { c += t.ExternalDocs.TotalChanges() } if t.ExtensionChanges != nil { - c += len(t.ExtensionChanges.Changes) + c += t.ExtensionChanges.TotalChanges() } return c } @@ -105,10 +105,9 @@ func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges { false, nil, seenRight[i].GetValue()) } } - - if len(changes) <= 0 { + tc.Changes = changes + if tc.TotalChanges() <= 0 { return nil } - tc.Changes = changes return tc } diff --git a/what-changed/xml.go b/what-changed/xml.go index d68ef5d..2fb0bc1 100644 --- a/what-changed/xml.go +++ b/what-changed/xml.go @@ -16,9 +16,9 @@ type XMLChanges struct { // TotalChanges returns a count of everything that was changed within an XML object. func (x *XMLChanges) TotalChanges() int { - c := len(x.Changes) + c := x.PropertyChanges.TotalChanges() if x.ExtensionChanges != nil { - c += len(x.ExtensionChanges.Changes) + c += x.ExtensionChanges.TotalChanges() } return c } @@ -97,7 +97,7 @@ func CompareXML(l, r *base.XML) *XMLChanges { // check extensions xc.ExtensionChanges = CheckExtensions(l, r) xc.Changes = changes - if len(xc.Changes) <= 0 && xc.ExtensionChanges == nil { + if xc.TotalChanges() <= 0 { return nil } return xc