-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtag.go
133 lines (115 loc) · 3.01 KB
/
tag.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"gopkg.in/yaml.v3"
)
type TagMap = ObjMap[*Tag]
// Tag adds metadata that is used by the Operation Object.
//
// It is not mandatory to have a Tag Object per tag defined in the Operation
// Object instances.
type Tag struct {
Location `json:"-"`
Extensions `json:"-"`
// The name of the tag.
//
// *required*
Name Text `json:"name"`
// A description for the tag.
//
// CommonMark syntax MAY be used for rich text representation.
//
// https://spec.commonmark.org/
Description Text `json:"description,omitempty"`
// Additional external documentation for this tag.
ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" bson:"externalDocs,omitempty"`
}
func (t *Tag) Nodes() []Node {
if t == nil {
return nil
}
return downcastNodes(t.nodes())
}
func (t *Tag) nodes() []node {
if t == nil {
return nil
}
return appendEdges(nil, t.ExternalDocs)
}
func (*Tag) Refs() []Ref { return nil }
func (*Tag) Anchors() (*Anchors, error) { return nil, nil }
func (t *Tag) isNil() bool { return t == nil }
// func (t *Tag) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if err := ptr.Validate(); err != nil {
// return nil, err
// }
// return t.resolveNodeByPointer(ptr)
// }
// func (t *Tag) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return t, nil
// }
// nxt, tok, _ := ptr.Next()
// switch tok {
// case "externalDocs":
// if nxt.IsRoot() {
// return t.ExternalDocs, nil
// }
// if t.ExternalDocs == nil {
// return nil, newErrNotFound(t.Location.AbsoluteLocation(), tok)
// }
// return t.ExternalDocs.resolveNodeByPointer(nxt)
// default:
// return nil, newErrNotResolvable(t.Location.AbsoluteLocation(), tok)
// }
// }
func (*Tag) Kind() Kind { return KindTag }
func (*Tag) mapKind() Kind { return KindUndefined }
func (*Tag) sliceKind() Kind { return KindTagSlice }
func (t *Tag) setLocation(loc Location) error {
if t == nil {
return nil
}
t.Location = loc
return t.ExternalDocs.setLocation(loc.AppendLocation("externalDocs"))
}
// MarshalJSON marshals t into JSON
func (t Tag) MarshalJSON() ([]byte, error) {
type tag Tag
return marshalExtendedJSON(tag(t))
}
// UnmarshalJSON unmarshals json into t
func (t *Tag) UnmarshalJSON(data []byte) error {
type tag Tag
v := tag{}
err := unmarshalExtendedJSON(data, &v)
*t = Tag(v)
return err
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
func (t Tag) MarshalYAML() (interface{}, error) {
j, err := t.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 satisfies gopkg.in/yaml.v3 Unmarshaler interface
func (t *Tag) 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, t)
}
var _ node = (*Tag)(nil)