mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
added custom renderer for change types.
Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user