-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinfo.go
174 lines (146 loc) · 4.02 KB
/
info.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package openapi
import (
"encoding/json"
"github.com/Masterminds/semver"
"github.com/chanced/transcode"
"gopkg.in/yaml.v3"
)
// Info provides metadata about the API. The metadata MAY be used by the clients
// if needed, and MAY be presented in editing or documentation generation tools
// for convenience.
type Info struct {
Extensions `json:"-"`
Location `json:"-"`
// Version of the OpenAPI document (which is distinct from the OpenAPI
// Specification version or the API implementation version).
//
// *required*
Version Text `json:"version"`
// The title of the API.
//
// *required*
Title Text `json:"title"`
// A short summary of the API.
Summary Text `json:"summary,omitempty"`
// A description of the API. CommonMark syntax MAY be used for rich text
// representation.
Description Text `json:"description,omitempty"`
// A URL to the Terms of Service for the API. This MUST be in the form of a
// URL.
TermsOfService Text `json:"termsOfService,omitempty" bson:"termsOfService,omitempty"`
// The contact information for the exposed API.
Contact *Contact `json:"contact,omitempty" bson:"contact,omitempty"`
// License information for the exposed API.
License *License `json:"license,omitempty" bson:"license,omitempty"`
}
func (*Info) Anchors() (*Anchors, error) { return nil, nil }
func (*Info) Kind() Kind { return KindInfo }
func (*Info) Refs() []Ref { return nil }
// func (i *Info) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// err := ptr.Validate()
// if err != nil {
// return nil, err
// }
// if ptr.IsRoot() {
// return i, nil
// }
// tok, _ := ptr.NextToken()
// switch tok {
// case "contact":
// if i.Contact == nil {
// return nil, newErrNotFound(i.absolute, tok)
// }
// return i.Contact, nil
// case "license":
// return i.License, nil
// }
// return nil, newErrNotResolvable(i.AbsoluteLocation(), tok)
// }
// func (i *Info) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return i, nil
// }
// tok, _ := ptr.NextToken()
// switch tok {
// case "contact":
// if i.Contact == nil {
// return nil, newErrNotFound(i.AbsoluteLocation(), tok)
// }
// return i.Contact, nil
// case "license":
// if i.License == nil {
// return nil, newErrNotFound(i.AbsoluteLocation(), tok)
// }
// return i.License, nil
// default:
// return nil, newErrNotResolvable(i.AbsoluteLocation(), tok)
// }
// }
func (i *Info) nodes() []node {
edges := appendEdges(nil, i.Contact)
edges = appendEdges(edges, i.License)
return edges
}
func (i *Info) isNil() bool {
return i == nil
}
func (i *Info) location() Location {
return i.Location
}
func (i *Info) SemVer() (*semver.Version, error) {
return semver.NewVersion(i.Version.String())
}
func (*Info) mapKind() Kind { return KindUndefined }
func (i *Info) setLocation(loc Location) error {
if i == nil {
return nil
}
i.Location = loc
if err := i.Contact.setLocation(loc.AppendLocation("contact")); err != nil {
return err
}
if err := i.License.setLocation(loc.AppendLocation("license")); err != nil {
return err
}
return nil
}
func (*Info) sliceKind() Kind { return KindUndefined }
// MarshalJSON marshals JSON
func (i Info) MarshalJSON() ([]byte, error) {
type info Info
return marshalExtendedJSON(info(i))
}
// UnmarshalJSON unmarshals JSON
func (i *Info) UnmarshalJSON(data []byte) error {
type info Info
var v info
err := unmarshalExtendedJSON(data, &v)
*i = Info(v)
return err
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
func (i Info) MarshalYAML() (interface{}, error) {
j, err := i.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 (i *Info) 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, i)
}
var _ node = (*Info)(nil)