-
Notifications
You must be signed in to change notification settings - Fork 2
/
contact.go
102 lines (86 loc) · 2.42 KB
/
contact.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"github.com/chanced/uri"
"gopkg.in/yaml.v3"
)
// Contact information for the exposed API.
type Contact struct {
Extensions `json:"-"`
Location `json:"-"`
// The identifying name of the contact person/organization.
Name Text `json:"name,omitempty"`
// The URL pointing to the contact information. This MUST be in the form of
// a URL.
URL *uri.URI `json:"url,omitempty"`
// The email address of the contact person/organization. This MUST be in the
// form of an email address.
Emails Text `json:"email,omitempty"`
}
func (*Contact) Anchors() (*Anchors, error) { return nil, nil }
// Kind returns KindContact
func (*Contact) Kind() Kind { return KindContact }
func (*Contact) Refs() []Ref { return nil }
// func (c *Contact) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if err := ptr.Validate(); err != nil {
// return nil, err
// }
// return c.resolveNodeByPointer(ptr)
// }
// func (c *Contact) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return c, nil
// }
// tok, _ := ptr.NextToken()
// return nil, newErrNotResolvable(c.AbsoluteLocation(), tok)
// }
func (*Contact) nodes() []node { return nil }
func (c *Contact) isNil() bool { return c == nil }
func (c *Contact) location() Location { return c.Location }
func (c *Contact) setLocation(loc Location) error {
if c != nil {
c.Location = loc
}
return nil
}
func (*Contact) sliceKind() Kind { return KindUndefined }
func (*Contact) mapKind() Kind { return KindUndefined }
// MarshalJSON marshals JSON
func (c Contact) MarshalJSON() ([]byte, error) {
type contact Contact
return marshalExtendedJSON(contact(c))
}
// UnmarshalJSON unmarshals JSON
func (c *Contact) UnmarshalJSON(data []byte) error {
type contact Contact
var v contact
err := unmarshalExtendedJSON(data, &v)
*c = Contact(v)
return err
}
func (c Contact) MarshalYAML() (interface{}, error) {
j, err := c.MarshalJSON()
if err != nil {
return nil, err
}
var v interface{}
err = json.Unmarshal(j, &v)
if err != nil {
return nil, err
}
return v, nil
}
// UnmarshalYAML implements yaml.Unmarshaler
func (c *Contact) UnmarshalYAML(value *yaml.Node) error {
v, err := yaml.Marshal(value)
if err != nil {
return err
}
j, err := transcode.JSONFromYAML(v)
if err != nil {
return err
}
return json.Unmarshal(j, c)
}
var _ node = (*Contact)(nil)