-
Notifications
You must be signed in to change notification settings - Fork 2
/
external_docs.go
126 lines (108 loc) · 3.18 KB
/
external_docs.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
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"github.com/chanced/uri"
"gopkg.in/yaml.v3"
)
// ExternalDocs allows referencing an external resource for extended
// documentation.
type ExternalDocs struct {
Location `json:"-"`
Extensions `json:"-"`
// The URL for the target documentation. This MUST be in the form of a URL.
//
// *required*
URL *uri.URI `json:"url"`
// A description of the target documentation. CommonMark syntax MAY be used
// for rich text representation.
Description Text `json:"description,omitempty"`
}
func (ed *ExternalDocs) Nodes() []Node {
if ed == nil {
return nil
}
return downcastNodes(ed.nodes())
}
func (ed *ExternalDocs) nodes() []node { return nil }
func (*ExternalDocs) Refs() []Ref { return nil }
func (*ExternalDocs) Kind() Kind { return KindExternalDocs }
func (*ExternalDocs) mapKind() Kind { return KindUndefined }
func (*ExternalDocs) sliceKind() Kind { return KindUndefined }
func (*ExternalDocs) Anchors() (*Anchors, error) { return nil, nil }
// // ResolveNodeByPointer resolves a Node by a jsonpointer. It validates the pointer and then
// // attempts to resolve the Node.
// //
// // # Errors
// //
// // - [ErrNotFound] indicates that the component was not found
// //
// // - [ErrNotResolvable] indicates that the pointer path can not resolve to a
// // Node
// //
// // - [jsonpointer.ErrMalformedEncoding] indicates that the pointer encoding
// // is malformed
// //
// // - [jsonpointer.ErrMalformedStart] indicates that the pointer is not empty
// // and does not start with a slash
// func (ed *ExternalDocs) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// err := ptr.Validate()
// if err != nil {
// return nil, err
// }
// return ed.resolveNodeByPointer(ptr)
// }
// func (ed *ExternalDocs) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// tok, _ := ptr.NextToken()
// if !ptr.IsRoot() {
// return nil, newErrNotResolvable(ed.Location.AbsoluteLocation(), tok)
// }
// return ed, nil
// }
// MarshalJSON marshals JSON
func (ed ExternalDocs) MarshalJSON() ([]byte, error) {
type externaldocs ExternalDocs
return marshalExtendedJSON(externaldocs(ed))
}
// UnmarshalJSON unmarshals JSON
func (ed *ExternalDocs) UnmarshalJSON(data []byte) error {
type externaldocs ExternalDocs
var v externaldocs
err := unmarshalExtendedJSON(data, &v)
*ed = ExternalDocs(v)
return err
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
func (ed ExternalDocs) MarshalYAML() (interface{}, error) {
j, err := ed.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 (ed *ExternalDocs) 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, ed)
}
func (ed *ExternalDocs) setLocation(loc Location) error {
if ed == nil {
return nil
}
ed.Location = loc
return nil
}
func (ed *ExternalDocs) isNil() bool { return ed == nil }
var _ node = (*ExternalDocs)(nil)