-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_metadata.go
64 lines (57 loc) · 1.97 KB
/
update_metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package models
import (
"encoding/json"
)
// UpdateMetadata represents a UpdateMetadata struct.
type UpdateMetadata struct {
CurrentName *string `json:"current_name,omitempty"`
Name *string `json:"name,omitempty"`
Value *string `json:"value,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for UpdateMetadata.
// It customizes the JSON marshaling process for UpdateMetadata objects.
func (u UpdateMetadata) MarshalJSON() (
[]byte,
error) {
return json.Marshal(u.toMap())
}
// toMap converts the UpdateMetadata object to a map representation for JSON marshaling.
func (u UpdateMetadata) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, u.AdditionalProperties)
if u.CurrentName != nil {
structMap["current_name"] = u.CurrentName
}
if u.Name != nil {
structMap["name"] = u.Name
}
if u.Value != nil {
structMap["value"] = u.Value
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for UpdateMetadata.
// It customizes the JSON unmarshaling process for UpdateMetadata objects.
func (u *UpdateMetadata) UnmarshalJSON(input []byte) error {
var temp updateMetadata
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "current_name", "name", "value")
if err != nil {
return err
}
u.AdditionalProperties = additionalProperties
u.CurrentName = temp.CurrentName
u.Name = temp.Name
u.Value = temp.Value
return nil
}
// updateMetadata is a temporary struct used for validating the fields of UpdateMetadata.
type updateMetadata struct {
CurrentName *string `json:"current_name,omitempty"`
Name *string `json:"name,omitempty"`
Value *string `json:"value,omitempty"`
}