added custom renderer for change types.

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2024-02-19 10:16:57 -05:00
parent 68c702dd7d
commit a6c5bdaf28

View File

@@ -4,6 +4,7 @@
package model
import (
"encoding/json"
"gopkg.in/yaml.v3"
)
@@ -92,6 +93,33 @@ type Change struct {
NewObject any `json:"-" yaml:"-"`
}
// MarshalJSON is a custom JSON marshaller for the Change object.
func (c *Change) MarshalJSON() ([]byte, error) {
changeType := ""
switch c.ChangeType {
case Modified:
changeType = "modified"
case PropertyAdded:
changeType = "property_added"
case ObjectAdded:
changeType = "object_added"
case ObjectRemoved:
changeType = "object_removed"
case PropertyRemoved:
changeType = "property_removed"
}
data := map[string]interface{}{
"change": c.ChangeType,
"changeText": changeType,
"context": c.Context,
"property": c.Property,
"original": c.Original,
"new": c.New,
"breaking": c.Breaking,
}
return json.Marshal(data)
}
// PropertyChanges holds a slice of Change pointers
type PropertyChanges struct {
//Total *int `json:"total,omitempty" yaml:"total,omitempty"`