Skip to content

Commit ebcbb72

Browse files
authored
Fix some golints (#530)
1 parent 869d5df commit ebcbb72

26 files changed

+354
-208
lines changed

openapi2/openapi2.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ type T struct {
2929
Tags openapi3.Tags `json:"tags,omitempty" yaml:"tags,omitempty"`
3030
}
3131

32+
// MarshalJSON returns the JSON encoding of T.
3233
func (doc *T) MarshalJSON() ([]byte, error) {
3334
return jsoninfo.MarshalStrictStruct(doc)
3435
}
3536

37+
// UnmarshalJSON sets T to a copy of data.
3638
func (doc *T) UnmarshalJSON(data []byte) error {
3739
return jsoninfo.UnmarshalStrictStruct(data, doc)
3840
}
@@ -64,10 +66,12 @@ type PathItem struct {
6466
Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`
6567
}
6668

69+
// MarshalJSON returns the JSON encoding of PathItem.
6770
func (pathItem *PathItem) MarshalJSON() ([]byte, error) {
6871
return jsoninfo.MarshalStrictStruct(pathItem)
6972
}
7073

74+
// UnmarshalJSON sets PathItem to a copy of data.
7175
func (pathItem *PathItem) UnmarshalJSON(data []byte) error {
7276
return jsoninfo.UnmarshalStrictStruct(data, pathItem)
7377
}
@@ -155,10 +159,12 @@ type Operation struct {
155159
Security *SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"`
156160
}
157161

162+
// MarshalJSON returns the JSON encoding of Operation.
158163
func (operation *Operation) MarshalJSON() ([]byte, error) {
159164
return jsoninfo.MarshalStrictStruct(operation)
160165
}
161166

167+
// UnmarshalJSON sets Operation to a copy of data.
162168
func (operation *Operation) UnmarshalJSON(data []byte) error {
163169
return jsoninfo.UnmarshalStrictStruct(data, operation)
164170
}
@@ -207,10 +213,12 @@ type Parameter struct {
207213
Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
208214
}
209215

216+
// MarshalJSON returns the JSON encoding of Parameter.
210217
func (parameter *Parameter) MarshalJSON() ([]byte, error) {
211218
return jsoninfo.MarshalStrictStruct(parameter)
212219
}
213220

221+
// UnmarshalJSON sets Parameter to a copy of data.
214222
func (parameter *Parameter) UnmarshalJSON(data []byte) error {
215223
return jsoninfo.UnmarshalStrictStruct(data, parameter)
216224
}
@@ -224,10 +232,12 @@ type Response struct {
224232
Examples map[string]interface{} `json:"examples,omitempty" yaml:"examples,omitempty"`
225233
}
226234

235+
// MarshalJSON returns the JSON encoding of Response.
227236
func (response *Response) MarshalJSON() ([]byte, error) {
228237
return jsoninfo.MarshalStrictStruct(response)
229238
}
230239

240+
// UnmarshalJSON sets Response to a copy of data.
231241
func (response *Response) UnmarshalJSON(data []byte) error {
232242
return jsoninfo.UnmarshalStrictStruct(data, response)
233243
}
@@ -236,10 +246,12 @@ type Header struct {
236246
Parameter
237247
}
238248

249+
// MarshalJSON returns the JSON encoding of Header.
239250
func (header *Header) MarshalJSON() ([]byte, error) {
240251
return jsoninfo.MarshalStrictStruct(header)
241252
}
242253

254+
// UnmarshalJSON sets Header to a copy of data.
243255
func (header *Header) UnmarshalJSON(data []byte) error {
244256
return jsoninfo.UnmarshalStrictStruct(data, header)
245257
}
@@ -260,10 +272,12 @@ type SecurityScheme struct {
260272
Tags openapi3.Tags `json:"tags,omitempty" yaml:"tags,omitempty"`
261273
}
262274

275+
// MarshalJSON returns the JSON encoding of SecurityScheme.
263276
func (securityScheme *SecurityScheme) MarshalJSON() ([]byte, error) {
264277
return jsoninfo.MarshalStrictStruct(securityScheme)
265278
}
266279

280+
// UnmarshalJSON sets SecurityScheme to a copy of data.
267281
func (securityScheme *SecurityScheme) UnmarshalJSON(data []byte) error {
268282
return jsoninfo.UnmarshalStrictStruct(data, securityScheme)
269283
}

openapi3/callback.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Callbacks map[string]*CallbackRef
1111

1212
var _ jsonpointer.JSONPointable = (*Callbacks)(nil)
1313

14+
// JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable
1415
func (c Callbacks) JSONLookup(token string) (interface{}, error) {
1516
ref, ok := c[token]
1617
if ref == nil || !ok {
@@ -27,8 +28,9 @@ func (c Callbacks) JSONLookup(token string) (interface{}, error) {
2728
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject
2829
type Callback map[string]*PathItem
2930

30-
func (value Callback) Validate(ctx context.Context) error {
31-
for _, v := range value {
31+
// Validate returns an error if Callback does not comply with the OpenAPI spec.
32+
func (callback Callback) Validate(ctx context.Context) error {
33+
for _, v := range callback {
3234
if err := v.Validate(ctx); err != nil {
3335
return err
3436
}

openapi3/components.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ func NewComponents() Components {
2828
return Components{}
2929
}
3030

31+
// MarshalJSON returns the JSON encoding of Components.
3132
func (components *Components) MarshalJSON() ([]byte, error) {
3233
return jsoninfo.MarshalStrictStruct(components)
3334
}
3435

36+
// UnmarshalJSON sets Components to a copy of data.
3537
func (components *Components) UnmarshalJSON(data []byte) error {
3638
return jsoninfo.UnmarshalStrictStruct(data, components)
3739
}
3840

41+
// Validate returns an error if Components does not comply with the OpenAPI spec.
3942
func (components *Components) Validate(ctx context.Context) (err error) {
4043
for k, v := range components.Schemas {
4144
if err = ValidateIdentifier(k); err != nil {

openapi3/content.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ func (content Content) Get(mime string) *MediaType {
104104
return content["*/*"]
105105
}
106106

107-
func (value Content) Validate(ctx context.Context) error {
108-
for _, v := range value {
109-
// Validate MediaType
107+
// Validate returns an error if Content does not comply with the OpenAPI spec.
108+
func (content Content) Validate(ctx context.Context) error {
109+
for _, v := range content {
110110
if err := v.Validate(ctx); err != nil {
111111
return err
112112
}

openapi3/discriminator.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ type Discriminator struct {
1515
Mapping map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
1616
}
1717

18-
func (value *Discriminator) MarshalJSON() ([]byte, error) {
19-
return jsoninfo.MarshalStrictStruct(value)
18+
// MarshalJSON returns the JSON encoding of Discriminator.
19+
func (discriminator *Discriminator) MarshalJSON() ([]byte, error) {
20+
return jsoninfo.MarshalStrictStruct(discriminator)
2021
}
2122

22-
func (value *Discriminator) UnmarshalJSON(data []byte) error {
23-
return jsoninfo.UnmarshalStrictStruct(data, value)
23+
// UnmarshalJSON sets Discriminator to a copy of data.
24+
func (discriminator *Discriminator) UnmarshalJSON(data []byte) error {
25+
return jsoninfo.UnmarshalStrictStruct(data, discriminator)
2426
}
2527

26-
func (value *Discriminator) Validate(ctx context.Context) error {
28+
// Validate returns an error if Discriminator does not comply with the OpenAPI spec.
29+
func (discriminator *Discriminator) Validate(ctx context.Context) error {
2730
return nil
2831
}

openapi3/encoding.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ func (encoding *Encoding) WithHeaderRef(name string, ref *HeaderRef) *Encoding {
3939
return encoding
4040
}
4141

42+
// MarshalJSON returns the JSON encoding of Encoding.
4243
func (encoding *Encoding) MarshalJSON() ([]byte, error) {
4344
return jsoninfo.MarshalStrictStruct(encoding)
4445
}
4546

47+
// UnmarshalJSON sets Encoding to a copy of data.
4648
func (encoding *Encoding) UnmarshalJSON(data []byte) error {
4749
return jsoninfo.UnmarshalStrictStruct(data, encoding)
4850
}
@@ -62,11 +64,12 @@ func (encoding *Encoding) SerializationMethod() *SerializationMethod {
6264
return sm
6365
}
6466

65-
func (value *Encoding) Validate(ctx context.Context) error {
66-
if value == nil {
67+
// Validate returns an error if Encoding does not comply with the OpenAPI spec.
68+
func (encoding *Encoding) Validate(ctx context.Context) error {
69+
if encoding == nil {
6770
return nil
6871
}
69-
for k, v := range value.Headers {
72+
for k, v := range encoding.Headers {
7073
if err := ValidateIdentifier(k); err != nil {
7174
return nil
7275
}
@@ -76,7 +79,7 @@ func (value *Encoding) Validate(ctx context.Context) error {
7679
}
7780

7881
// Validate a media types's serialization method.
79-
sm := value.SerializationMethod()
82+
sm := encoding.SerializationMethod()
8083
switch {
8184
case sm.Style == SerializationForm && sm.Explode,
8285
sm.Style == SerializationForm && !sm.Explode,

openapi3/example.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Examples map[string]*ExampleRef
1212

1313
var _ jsonpointer.JSONPointable = (*Examples)(nil)
1414

15+
// JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable
1516
func (e Examples) JSONLookup(token string) (interface{}, error) {
1617
ref, ok := e[token]
1718
if ref == nil || !ok {
@@ -41,14 +42,17 @@ func NewExample(value interface{}) *Example {
4142
}
4243
}
4344

45+
// MarshalJSON returns the JSON encoding of Example.
4446
func (example *Example) MarshalJSON() ([]byte, error) {
4547
return jsoninfo.MarshalStrictStruct(example)
4648
}
4749

50+
// UnmarshalJSON sets Example to a copy of data.
4851
func (example *Example) UnmarshalJSON(data []byte) error {
4952
return jsoninfo.UnmarshalStrictStruct(data, example)
5053
}
5154

52-
func (value *Example) Validate(ctx context.Context) error {
55+
// Validate returns an error if Example does not comply with the OpenAPI spec.
56+
func (example *Example) Validate(ctx context.Context) error {
5357
return nil // TODO
5458
}

openapi3/external_docs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ type ExternalDocs struct {
1818
URL string `json:"url,omitempty" yaml:"url,omitempty"`
1919
}
2020

21+
// MarshalJSON returns the JSON encoding of ExternalDocs.
2122
func (e *ExternalDocs) MarshalJSON() ([]byte, error) {
2223
return jsoninfo.MarshalStrictStruct(e)
2324
}
2425

26+
// UnmarshalJSON sets ExternalDocs to a copy of data.
2527
func (e *ExternalDocs) UnmarshalJSON(data []byte) error {
2628
return jsoninfo.UnmarshalStrictStruct(data, e)
2729
}
2830

31+
// Validate returns an error if ExternalDocs does not comply with the OpenAPI spec.
2932
func (e *ExternalDocs) Validate(ctx context.Context) error {
3033
if e.URL == "" {
3134
return errors.New("url is required")

openapi3/header.go

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Headers map[string]*HeaderRef
1313

1414
var _ jsonpointer.JSONPointable = (*Headers)(nil)
1515

16+
// JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable
1617
func (h Headers) JSONLookup(token string) (interface{}, error) {
1718
ref, ok := h[token]
1819
if ref == nil || !ok {
@@ -33,33 +34,35 @@ type Header struct {
3334

3435
var _ jsonpointer.JSONPointable = (*Header)(nil)
3536

36-
func (value *Header) UnmarshalJSON(data []byte) error {
37-
return jsoninfo.UnmarshalStrictStruct(data, value)
37+
// UnmarshalJSON sets Header to a copy of data.
38+
func (header *Header) UnmarshalJSON(data []byte) error {
39+
return jsoninfo.UnmarshalStrictStruct(data, header)
3840
}
3941

4042
// SerializationMethod returns a header's serialization method.
41-
func (value *Header) SerializationMethod() (*SerializationMethod, error) {
42-
style := value.Style
43+
func (header *Header) SerializationMethod() (*SerializationMethod, error) {
44+
style := header.Style
4345
if style == "" {
4446
style = SerializationSimple
4547
}
4648
explode := false
47-
if value.Explode != nil {
48-
explode = *value.Explode
49+
if header.Explode != nil {
50+
explode = *header.Explode
4951
}
5052
return &SerializationMethod{Style: style, Explode: explode}, nil
5153
}
5254

53-
func (value *Header) Validate(ctx context.Context) error {
54-
if value.Name != "" {
55+
// Validate returns an error if Header does not comply with the OpenAPI spec.
56+
func (header *Header) Validate(ctx context.Context) error {
57+
if header.Name != "" {
5558
return errors.New("header 'name' MUST NOT be specified, it is given in the corresponding headers map")
5659
}
57-
if value.In != "" {
60+
if header.In != "" {
5861
return errors.New("header 'in' MUST NOT be specified, it is implicitly in header")
5962
}
6063

6164
// Validate a parameter's serialization method.
62-
sm, err := value.SerializationMethod()
65+
sm, err := header.SerializationMethod()
6366
if err != nil {
6467
return err
6568
}
@@ -70,59 +73,60 @@ func (value *Header) Validate(ctx context.Context) error {
7073
return fmt.Errorf("header schema is invalid: %v", e)
7174
}
7275

73-
if (value.Schema == nil) == (value.Content == nil) {
74-
e := fmt.Errorf("parameter must contain exactly one of content and schema: %v", value)
76+
if (header.Schema == nil) == (header.Content == nil) {
77+
e := fmt.Errorf("parameter must contain exactly one of content and schema: %v", header)
7578
return fmt.Errorf("header schema is invalid: %v", e)
7679
}
77-
if schema := value.Schema; schema != nil {
80+
if schema := header.Schema; schema != nil {
7881
if err := schema.Validate(ctx); err != nil {
7982
return fmt.Errorf("header schema is invalid: %v", err)
8083
}
8184
}
8285

83-
if content := value.Content; content != nil {
86+
if content := header.Content; content != nil {
8487
if err := content.Validate(ctx); err != nil {
8588
return fmt.Errorf("header content is invalid: %v", err)
8689
}
8790
}
8891
return nil
8992
}
9093

91-
func (value Header) JSONLookup(token string) (interface{}, error) {
94+
// JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable
95+
func (header Header) JSONLookup(token string) (interface{}, error) {
9296
switch token {
9397
case "schema":
94-
if value.Schema != nil {
95-
if value.Schema.Ref != "" {
96-
return &Ref{Ref: value.Schema.Ref}, nil
98+
if header.Schema != nil {
99+
if header.Schema.Ref != "" {
100+
return &Ref{Ref: header.Schema.Ref}, nil
97101
}
98-
return value.Schema.Value, nil
102+
return header.Schema.Value, nil
99103
}
100104
case "name":
101-
return value.Name, nil
105+
return header.Name, nil
102106
case "in":
103-
return value.In, nil
107+
return header.In, nil
104108
case "description":
105-
return value.Description, nil
109+
return header.Description, nil
106110
case "style":
107-
return value.Style, nil
111+
return header.Style, nil
108112
case "explode":
109-
return value.Explode, nil
113+
return header.Explode, nil
110114
case "allowEmptyValue":
111-
return value.AllowEmptyValue, nil
115+
return header.AllowEmptyValue, nil
112116
case "allowReserved":
113-
return value.AllowReserved, nil
117+
return header.AllowReserved, nil
114118
case "deprecated":
115-
return value.Deprecated, nil
119+
return header.Deprecated, nil
116120
case "required":
117-
return value.Required, nil
121+
return header.Required, nil
118122
case "example":
119-
return value.Example, nil
123+
return header.Example, nil
120124
case "examples":
121-
return value.Examples, nil
125+
return header.Examples, nil
122126
case "content":
123-
return value.Content, nil
127+
return header.Content, nil
124128
}
125129

126-
v, _, err := jsonpointer.GetForToken(value.ExtensionProps, token)
130+
v, _, err := jsonpointer.GetForToken(header.ExtensionProps, token)
127131
return v, err
128132
}

0 commit comments

Comments
 (0)