what_changed

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Modified means that was a modification of a value was made
	Modified = iota + 1

	// PropertyAdded means that a new property to an object was added
	PropertyAdded

	// ObjectAdded means that a new object was added
	ObjectAdded

	// ObjectRemoved means that an object was removed
	ObjectRemoved

	// PropertyRemoved means that a property of an object was removed
	PropertyRemoved
)

Definitions of the possible changes between two items

Variables

This section is empty.

Functions

func CheckForAddition

func CheckForAddition[T any](l, r *yaml.Node, label string, changes *[]*Change[T], breaking bool, orig, new T)

CheckForAddition will check left and right yaml.Node instances for changes. Anything that is found missing on the left, but present on the left, is considered an addition. A new Change[T] will be created with the type

PropertyAdded

The Change is then added to the slice of []Change[T] instances provided as a pointer.

func CheckForModification

func CheckForModification[T any](l, r *yaml.Node, label string, changes *[]*Change[T], breaking bool, orig, new T)

CheckForModification will check left and right yaml.Node instances for changes. Anything that is found in both sides, but vary in value is considered a modification.

If there is a change in value the function adds a change type of Modified.

The Change is then added to the slice of []Change[T] instances provided as a pointer.

func CheckForObjectAdditionOrRemoval

func CheckForObjectAdditionOrRemoval[T any](l, r map[string]*low.ValueReference[T], label string, changes *[]*Change[T],
	breakingAdd, breakingRemove bool)

CheckForObjectAdditionOrRemoval will check for the addition or removal of an object from left and right maps. The label is the key to look for in the left and right maps.

To determine this a breaking change for an addition then set breakingAdd to true (however I can't think of many scenarios that adding things should break anything). Removals are generally breaking, except for non contract properties like descriptions, summaries and other non-binding values, so a breakingRemove value can be tuned for these circumstances.

func CheckForRemoval

func CheckForRemoval[T any](l, r *yaml.Node, label string, changes *[]*Change[T], breaking bool, orig, new T)

CheckForRemoval will check left and right yaml.Node instances for changes. Anything that is found missing on the right, but present on the left, is considered a removal. A new Change[T] will be created with the type

PropertyRemoved

The Change is then added to the slice of []Change[T] instances provided as a pointer.

func CheckProperties

func CheckProperties[T any](properties []*PropertyCheck[T])

CheckProperties will iterate through a slice of PropertyCheck pointers of type T. The method is a convenience method for running checks on the following methods in order:

CheckPropertyAdditionOrRemoval
CheckForModification

func CheckPropertyAdditionOrRemoval

func CheckPropertyAdditionOrRemoval[T any](l, r *yaml.Node,
	label string, changes *[]*Change[T], breaking bool, orig, new T)

CheckPropertyAdditionOrRemoval will run both CheckForRemoval (first) and CheckForAddition (second)

func CheckSpecificObjectAdded

func CheckSpecificObjectAdded[T any](l, r map[string]*T, label string) bool

CheckSpecificObjectAdded returns true if a specific value is not in both maps.

func CheckSpecificObjectRemoved

func CheckSpecificObjectRemoved[T any](l, r map[string]*T, label string) bool

CheckSpecificObjectRemoved returns true if a specific value is not in both maps.

func CountBreakingChanges

func CountBreakingChanges[T any](changes []*Change[T]) int

CountBreakingChanges counts the number of changes in a slice that are breaking

func CreateChange

func CreateChange[T any](changes *[]*Change[T], changeType int, property string, leftValueNode, rightValueNode *yaml.Node,
	breaking bool, originalObject, newObject any) *[]*Change[T]

CreateChange is a generic function that will create a Change of type T, populate all properties if set, and then add a pointer to Change[T] in the slice of Change pointers provided

func FlattenLowLevelMap

func FlattenLowLevelMap[T any](
	lowMap map[low.KeyReference[string]]low.ValueReference[T]) map[string]*low.ValueReference[T]

Types

type Change

type Change[T any] struct {

	// Context represents the lines and column numbers of the original and new values
	// It's worth noting that these values may frequently be different and are not used to calculate
	// a change. If the positions change, but values do not, then no change is recorded.
	Context *ChangeContext

	// ChangeType represents the type of change that occurred. stored as an integer, defined by constants above.
	ChangeType int

	// Property is the property name key being changed.
	Property string

	// Original is the original value represented as a string.
	Original string

	// New is the new value represented as a string.
	New string

	// Breaking determines if the change is a breaking one or not.
	Breaking bool

	// OriginalObject represents the original object that was changed.
	OriginalObject any

	// NewObject represents the new object that has been modified.
	NewObject any
}

Change represents a change between two different elements inside an OpenAPI specification.

type ChangeContext

type ChangeContext struct {
	OriginalLine   int
	OriginalColumn int
	NewLine        int
	NewColumn      int
}

ChangeContext holds a reference to the line and column positions of original and new change.

func CreateContext

func CreateContext(l, r *yaml.Node) *ChangeContext

CreateContext will return a pointer to a ChangeContext containing the original and new line and column numbers of the left and right value nodes.

func (*ChangeContext) HasChanged

func (c *ChangeContext) HasChanged() bool

HasChanged determines if the line and column numbers of the original and new values have changed.

It's worth noting that there is no guarantee to the positions of anything in either left or right, so considering these values as 'changes' is going to add a considerable amount of noise to results.

type Changes

type Changes struct {
	TagChanges *TagChanges
}

type ContactChanges

type ContactChanges struct {
	PropertyChanges[*base.Contact]
}

ContactChanges Represent changes to a Contact object that is a child of Info, part of an OpenAPI document.

func CompareContact

func CompareContact(l, r *base.Contact) *ContactChanges

CompareContact will check a left (original) and right (new) Contact object for any changes. If there were any, a pointer to a ContactChanges object is returned, otherwise if nothing changed - the function returns nil.

func (*ContactChanges) TotalBreakingChanges

func (c *ContactChanges) TotalBreakingChanges() int

TotalBreakingChanges always returns 0 for Contact objects, they are non-binding.

func (*ContactChanges) TotalChanges

func (c *ContactChanges) TotalChanges() int

TotalChanges represents the total number of changes that have occurred to a Contact object

type DiscriminatorChanges

type DiscriminatorChanges struct {
	PropertyChanges[*base.Discriminator]
	MappingChanges []*Change[string]
}

DiscriminatorChanges represents changes made to a Discriminator OpenAPI object

func CompareDiscriminator

func CompareDiscriminator(l, r *base.Discriminator) *DiscriminatorChanges

CompareDiscriminator will check a left (original) and right (new) Discriminator object for changes and will return a pointer to DiscriminatorChanges

func (*DiscriminatorChanges) TotalBreakingChanges

func (d *DiscriminatorChanges) TotalBreakingChanges() int

TotalBreakingChanges returns the number of breaking changes made by the Discriminator

func (*DiscriminatorChanges) TotalChanges

func (d *DiscriminatorChanges) TotalChanges() int

TotalChanges returns a count of everything changed within the Discriminator object

type ExampleChanges

type ExampleChanges struct {
	PropertyChanges[*base.Example]
	ExtensionChanges *ExtensionChanges
}

ExampleChanges represent changes to an Example object, part of an OpenAPI specification.

func CompareExamples

func CompareExamples(l, r *base.Example) *ExampleChanges

func (*ExampleChanges) TotalChanges

func (e *ExampleChanges) TotalChanges() int

TotalChanges returns the total number of changes made to Example

type ExtensionChanges

type ExtensionChanges struct {
	PropertyChanges[any]
}

ExtensionChanges represents any changes to custom extensions defined for an OpenAPI object.

func CheckExtensions

func CheckExtensions[T low.HasExtensions[T]](l, r T) *ExtensionChanges

CheckExtensions is a helper method to un-pack a left and right model that contains extensions. Once unpacked the extensions are compared and returns a pointer to ExtensionChanges. If nothing changed, nil is returned.

func CompareExtensions

func CompareExtensions(l, r map[low.KeyReference[string]]low.ValueReference[any]) *ExtensionChanges

CompareExtensions will compare a left and right map of Key/ValueReference models for any changes to anything. This function does not try and cast the value of an extension to perform checks, it will perform a basic value check.

A current limitation relates to extensions being objects and a property of the object changes, there is currently no support for knowing anything changed - so it is ignored.

func (*ExtensionChanges) TotalBreakingChanges

func (e *ExtensionChanges) TotalBreakingChanges() int

TotalBreakingChanges always returns 0 for Extension objects, they are non-binding.

func (*ExtensionChanges) TotalChanges

func (e *ExtensionChanges) TotalChanges() int

type ExternalDocChanges

type ExternalDocChanges struct {
	PropertyChanges[*base.ExternalDoc]
	ExtensionChanges *ExtensionChanges
}

ExternalDocChanges represents changes made to any ExternalDoc object from an OpenAPI document.

func CompareExternalDocs

func CompareExternalDocs(l, r *base.ExternalDoc) *ExternalDocChanges

CompareExternalDocs will compare a left (original) and a right (new) slice of ValueReference nodes for any changes between them. If there are changes, then a pointer to ExternalDocChanges is returned, otherwise if nothing changed - then nil is returned.

func (*ExternalDocChanges) TotalBreakingChanges

func (e *ExternalDocChanges) TotalBreakingChanges() int

TotalBreakingChanges always returns 0 for ExternalDoc objects, they are non-binding.

func (*ExternalDocChanges) TotalChanges

func (e *ExternalDocChanges) TotalChanges() int

TotalChanges returns a count of everything that changed

type InfoChanges

type InfoChanges struct {
	PropertyChanges[*base.Info]
	ContactChanges *ContactChanges
	LicenseChanges *LicenseChanges
}

InfoChanges represents the number of changes to an Info object. Part of an OpenAPI document

func CompareInfo

func CompareInfo(l, r *base.Info) *InfoChanges

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 (*InfoChanges) TotalBreakingChanges

func (i *InfoChanges) TotalBreakingChanges() int

TotalBreakingChanges always returns 0 for Info objects, they are non-binding.

func (*InfoChanges) TotalChanges

func (i *InfoChanges) TotalChanges() int

TotalChanges represents the total number of changes made to an Info object.

type LicenseChanges

type LicenseChanges struct {
	PropertyChanges[*base.License]
}

LicenseChanges represent changes to a License object that is a child of Info object. Part of an OpenAPI document

func CompareLicense

func CompareLicense(l, r *base.License) *LicenseChanges

CompareLicense will check a left (original) and right (new) License object for any changes. If there were any, a pointer to a LicenseChanges object is returned, otherwise if nothing changed - the function returns nil.

func (*LicenseChanges) TotalBreakingChanges

func (l *LicenseChanges) TotalBreakingChanges() int

TotalBreakingChanges always returns 0 for License objects, they are non-binding.

func (*LicenseChanges) TotalChanges

func (l *LicenseChanges) TotalChanges() int

TotalChanges represents the total number of changes made to a License instance.

type PropertyChanges

type PropertyChanges[T any] struct {
	Changes []*Change[T]
}

PropertyChanges holds a slice of Change[T] change pointers

func (PropertyChanges[T]) TotalBreakingChanges

func (p PropertyChanges[T]) TotalBreakingChanges() int

TotalBreakingChanges returns the total number of property breaking changes made.

func (PropertyChanges[T]) TotalChanges

func (p PropertyChanges[T]) TotalChanges() int

TotalChanges returns the total number of property changes made.

type PropertyCheck

type PropertyCheck[T any] struct {

	// Original is the property we're checking on the left
	Original T

	// New is s the property we're checking on the right
	New T

	// Label is the identifier we're looking for on the left and right hand sides
	Label string

	// LeftNode is the yaml.Node pointer that holds the original node structure of the value
	LeftNode *yaml.Node

	// RightNode is the yaml.Node pointer that holds the new node structure of the value
	RightNode *yaml.Node

	// Breaking determines if the check is a breaking change (modifications or removals etc.)
	Breaking bool

	// Changes represents a pointer to the slice to contain all changes found.
	Changes *[]*Change[T]
}

PropertyCheck is used by functions to check the state of left and right values.

type SchemaChanges

type SchemaChanges struct {
	PropertyChanges[*base.Schema]
	DiscriminatorChanges  *DiscriminatorChanges
	AllOfChanges          []*SchemaChanges
	AnyOfChanges          []*SchemaChanges
	OneOfChanges          []*SchemaChanges
	NotChanges            []*SchemaChanges
	ItemsChanges          []*SchemaChanges
	SchemaPropertyChanges map[string]*SchemaChanges
	ExternalDocChanges    *ExternalDocChanges
	XMLChanges            *XMLChanges
	ExtensionChanges      *ExtensionChanges
}

func CompareSchemas

func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges

func (*SchemaChanges) TotalBreakingChanges

func (s *SchemaChanges) TotalBreakingChanges() int

func (*SchemaChanges) TotalChanges

func (s *SchemaChanges) TotalChanges() int

type TagChanges

type TagChanges struct {
	PropertyChanges[*base.Tag]
	ExternalDocs     *ExternalDocChanges
	ExtensionChanges *ExtensionChanges
}

TagChanges represents changes made to the Tags object of an OpenAPI document.

func CompareTags

func CompareTags(l, r []low.ValueReference[*base.Tag]) *TagChanges

CompareTags will compare a left (original) and a right (new) slice of ValueReference nodes for any changes between them. If there are changes, a pointer to TagChanges is returned, if not then nil is returned instead.

func (*TagChanges) TotalBreakingChanges

func (t *TagChanges) TotalBreakingChanges() int

TotalBreakingChanges returns the number of breaking changes made by Tags

func (*TagChanges) TotalChanges

func (t *TagChanges) TotalChanges() int

TotalChanges returns a count of everything that changed within tags.

type WhatChanged

type WhatChanged struct {
	Added            int
	Removed          int
	ModifiedAndMoved int
	Modified         int
	Moved            int
	TotalChanges     int
	Changes          *Changes
}

WhatChanged is a summary object that contains a high level summary of everything changed.

type XMLChanges

type XMLChanges struct {
	PropertyChanges[*base.XML]
	ExtensionChanges *ExtensionChanges
}

XMLChanges represents changes made to the XML object of an OpenAPI document.

func CompareXML

func CompareXML(l, r *base.XML) *XMLChanges

CompareXML will compare a left (original) and a right (new) XML instance, and check for any changes between them. If changes are found, the function returns a pointer to XMLChanges, otherwise, if nothing changed - it will return nil

func (*XMLChanges) TotalBreakingChanges

func (x *XMLChanges) TotalBreakingChanges() int

TotalBreakingChanges returns the number of breaking changes made by the XML object.

func (*XMLChanges) TotalChanges

func (x *XMLChanges) TotalChanges() int

TotalChanges returns a count of everything that was changed within an XML object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL