Skip to content

Commit 5f67f43

Browse files
authored
follow lint rules (#250)
1 parent ceae068 commit 5f67f43

21 files changed

Lines changed: 398 additions & 499 deletions

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import (
7878

7979
func main() {
8080
router := openapi3filter.NewRouter().WithSwaggerFromFile("swagger.json")
81-
ctx := context.TODO()
81+
ctx := context.Background()
8282
httpReq, _ := http.NewRequest(http.MethodGet, "/items", nil)
8383

8484
// Find route
@@ -105,9 +105,7 @@ func main() {
105105
RequestValidationInput: requestValidationInput,
106106
Status: respStatus,
107107
Header: http.Header{
108-
"Content-Type": []string{
109-
respContentType,
110-
},
108+
"Content-Type": []string{respContentType},
111109
},
112110
}
113111
if respBody != nil {

jsoninfo/unmarshal_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package jsoninfo_test
1+
package jsoninfo
22

33
import (
44
"errors"
55
"testing"
66

7-
"github.com/getkin/kin-openapi/jsoninfo"
87
"github.com/stretchr/testify/assert"
98
)
109

@@ -16,7 +15,7 @@ func TestNewObjectDecoder(t *testing.T) {
1615
}
1716
`)
1817
t.Run("test new object decoder", func(t *testing.T) {
19-
decoder, err := jsoninfo.NewObjectDecoder(data)
18+
decoder, err := NewObjectDecoder(data)
2019
assert.Nil(t, err)
2120
assert.NotNil(t, decoder)
2221
assert.Equal(t, data, decoder.Data)
@@ -25,15 +24,15 @@ func TestNewObjectDecoder(t *testing.T) {
2524
}
2625

2726
type mockStrictStruct struct {
28-
EncodeWithFn func(encoder *jsoninfo.ObjectEncoder, value interface{}) error
29-
DecodeWithFn func(decoder *jsoninfo.ObjectDecoder, value interface{}) error
27+
EncodeWithFn func(encoder *ObjectEncoder, value interface{}) error
28+
DecodeWithFn func(decoder *ObjectDecoder, value interface{}) error
3029
}
3130

32-
func (m *mockStrictStruct) EncodeWith(encoder *jsoninfo.ObjectEncoder, value interface{}) error {
31+
func (m *mockStrictStruct) EncodeWith(encoder *ObjectEncoder, value interface{}) error {
3332
return m.EncodeWithFn(encoder, value)
3433
}
3534

36-
func (m *mockStrictStruct) DecodeWith(decoder *jsoninfo.ObjectDecoder, value interface{}) error {
35+
func (m *mockStrictStruct) DecodeWith(decoder *ObjectDecoder, value interface{}) error {
3736
return m.DecodeWithFn(decoder, value)
3837
}
3938

@@ -48,31 +47,31 @@ func TestUnmarshalStrictStruct(t *testing.T) {
4847
t.Run("test unmarshal with StrictStruct without err", func(t *testing.T) {
4948
decodeWithFnCalled := 0
5049
mockStruct := &mockStrictStruct{
51-
EncodeWithFn: func(encoder *jsoninfo.ObjectEncoder, value interface{}) error {
50+
EncodeWithFn: func(encoder *ObjectEncoder, value interface{}) error {
5251
return nil
5352
},
54-
DecodeWithFn: func(decoder *jsoninfo.ObjectDecoder, value interface{}) error {
53+
DecodeWithFn: func(decoder *ObjectDecoder, value interface{}) error {
5554
decodeWithFnCalled++
5655
return nil
5756
},
5857
}
59-
err := jsoninfo.UnmarshalStrictStruct(data, mockStruct)
58+
err := UnmarshalStrictStruct(data, mockStruct)
6059
assert.Nil(t, err)
6160
assert.Equal(t, 1, decodeWithFnCalled)
6261
})
6362

6463
t.Run("test unmarshal with StrictStruct with err", func(t *testing.T) {
6564
decodeWithFnCalled := 0
6665
mockStruct := &mockStrictStruct{
67-
EncodeWithFn: func(encoder *jsoninfo.ObjectEncoder, value interface{}) error {
66+
EncodeWithFn: func(encoder *ObjectEncoder, value interface{}) error {
6867
return nil
6968
},
70-
DecodeWithFn: func(decoder *jsoninfo.ObjectDecoder, value interface{}) error {
69+
DecodeWithFn: func(decoder *ObjectDecoder, value interface{}) error {
7170
decodeWithFnCalled++
7271
return errors.New("unable to decode the value")
7372
},
7473
}
75-
err := jsoninfo.UnmarshalStrictStruct(data, mockStruct)
74+
err := UnmarshalStrictStruct(data, mockStruct)
7675
assert.NotNil(t, err)
7776
assert.Equal(t, 1, decodeWithFnCalled)
7877
})
@@ -85,7 +84,7 @@ func TestDecodeStructFieldsAndExtensions(t *testing.T) {
8584
"field2": "field2"
8685
}
8786
`)
88-
decoder, err := jsoninfo.NewObjectDecoder(data)
87+
decoder, err := NewObjectDecoder(data)
8988
assert.Nil(t, err)
9089
assert.NotNil(t, decoder)
9190

@@ -111,7 +110,7 @@ func TestDecodeStructFieldsAndExtensions(t *testing.T) {
111110
})
112111

113112
t.Run("successfully decoded with all fields", func(t *testing.T) {
114-
d, err := jsoninfo.NewObjectDecoder(data)
113+
d, err := NewObjectDecoder(data)
115114
assert.Nil(t, err)
116115
assert.NotNil(t, d)
117116

@@ -127,7 +126,7 @@ func TestDecodeStructFieldsAndExtensions(t *testing.T) {
127126
})
128127

129128
t.Run("successfully decoded with renaming field", func(t *testing.T) {
130-
d, err := jsoninfo.NewObjectDecoder(data)
129+
d, err := NewObjectDecoder(data)
131130
assert.Nil(t, err)
132131
assert.NotNil(t, d)
133132

@@ -141,7 +140,7 @@ func TestDecodeStructFieldsAndExtensions(t *testing.T) {
141140
})
142141

143142
t.Run("un-successfully decoded due to data mismatch", func(t *testing.T) {
144-
d, err := jsoninfo.NewObjectDecoder(data)
143+
d, err := NewObjectDecoder(data)
145144
assert.Nil(t, err)
146145
assert.NotNil(t, d)
147146

openapi3/discriminator_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
package openapi3_test
1+
package openapi3
22

33
import (
44
"testing"
55

6-
"github.com/getkin/kin-openapi/openapi3"
76
"github.com/stretchr/testify/require"
87
)
98

@@ -37,7 +36,7 @@ var jsonSpecWithDiscriminator = []byte(`
3736
`)
3837

3938
func TestParsingDiscriminator(t *testing.T) {
40-
loader, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData(jsonSpecWithDiscriminator)
39+
loader, err := NewSwaggerLoader().LoadSwaggerFromData(jsonSpecWithDiscriminator)
4140
require.NoError(t, err)
4241
require.Equal(t, 2, len(loader.Components.Schemas["MyResponseType"].Value.OneOf))
4342
}

openapi3/encoding_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package openapi3_test
1+
package openapi3
22

33
import (
44
"context"
55
"encoding/json"
66
"reflect"
77
"testing"
88

9-
"github.com/getkin/kin-openapi/openapi3"
109
"github.com/stretchr/testify/require"
1110
)
1211

@@ -17,13 +16,13 @@ func TestEncodingJSON(t *testing.T) {
1716
require.NotEmpty(t, data)
1817

1918
t.Log("Unmarshal *openapi3.Encoding from JSON")
20-
docA := &openapi3.Encoding{}
19+
docA := &Encoding{}
2120
err = json.Unmarshal(encodingJSON, &docA)
2221
require.NoError(t, err)
2322
require.NotEmpty(t, data)
2423

2524
t.Log("Validate *openapi3.Encoding")
26-
err = docA.Validate(context.TODO())
25+
err = docA.Validate(context.Background())
2726
require.NoError(t, err)
2827

2928
t.Log("Ensure representations match")
@@ -45,13 +44,13 @@ var encodingJSON = []byte(`
4544
}
4645
`)
4746

48-
func encoding() *openapi3.Encoding {
47+
func encoding() *Encoding {
4948
explode := true
50-
return &openapi3.Encoding{
49+
return &Encoding{
5150
ContentType: "application/json",
52-
Headers: map[string]*openapi3.HeaderRef{
51+
Headers: map[string]*HeaderRef{
5352
"someHeader": {
54-
Value: &openapi3.Header{},
53+
Value: &Header{},
5554
},
5655
},
5756
Style: "form",
@@ -64,32 +63,32 @@ func TestEncodingSerializationMethod(t *testing.T) {
6463
boolPtr := func(b bool) *bool { return &b }
6564
testCases := []struct {
6665
name string
67-
enc *openapi3.Encoding
68-
want *openapi3.SerializationMethod
66+
enc *Encoding
67+
want *SerializationMethod
6968
}{
7069
{
7170
name: "default",
72-
want: &openapi3.SerializationMethod{Style: openapi3.SerializationForm, Explode: true},
71+
want: &SerializationMethod{Style: SerializationForm, Explode: true},
7372
},
7473
{
7574
name: "encoding with style",
76-
enc: &openapi3.Encoding{Style: openapi3.SerializationSpaceDelimited},
77-
want: &openapi3.SerializationMethod{Style: openapi3.SerializationSpaceDelimited, Explode: true},
75+
enc: &Encoding{Style: SerializationSpaceDelimited},
76+
want: &SerializationMethod{Style: SerializationSpaceDelimited, Explode: true},
7877
},
7978
{
8079
name: "encoding with explode",
81-
enc: &openapi3.Encoding{Explode: boolPtr(true)},
82-
want: &openapi3.SerializationMethod{Style: openapi3.SerializationForm, Explode: true},
80+
enc: &Encoding{Explode: boolPtr(true)},
81+
want: &SerializationMethod{Style: SerializationForm, Explode: true},
8382
},
8483
{
8584
name: "encoding with no explode",
86-
enc: &openapi3.Encoding{Explode: boolPtr(false)},
87-
want: &openapi3.SerializationMethod{Style: openapi3.SerializationForm, Explode: false},
85+
enc: &Encoding{Explode: boolPtr(false)},
86+
want: &SerializationMethod{Style: SerializationForm, Explode: false},
8887
},
8988
{
9089
name: "encoding with style and explode ",
91-
enc: &openapi3.Encoding{Style: openapi3.SerializationSpaceDelimited, Explode: boolPtr(false)},
92-
want: &openapi3.SerializationMethod{Style: openapi3.SerializationSpaceDelimited, Explode: false},
90+
enc: &Encoding{Style: SerializationSpaceDelimited, Explode: boolPtr(false)},
91+
want: &SerializationMethod{Style: SerializationSpaceDelimited, Explode: false},
9392
},
9493
}
9594
for _, tc := range testCases {

openapi3/example_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package openapi3_test
1+
package openapi3
22

33
import (
44
"encoding/json"
55
"testing"
66

7-
"github.com/getkin/kin-openapi/openapi3"
87
"github.com/stretchr/testify/require"
98
)
109

@@ -15,7 +14,7 @@ func TestExampleJSON(t *testing.T) {
1514
require.NotEmpty(t, data)
1615

1716
t.Log("Unmarshal *openapi3.Example from JSON")
18-
docA := &openapi3.Example{}
17+
docA := &Example{}
1918
err = json.Unmarshal(exampleJSON, &docA)
2019
require.NoError(t, err)
2120
require.NotEmpty(t, data)
@@ -40,15 +39,15 @@ var exampleJSON = []byte(`
4039
}
4140
`)
4241

43-
func example() *openapi3.Example {
42+
func example() *Example {
4443
value := map[string]string{
4544
"name": "Fluffy",
4645
"petType": "Cat",
4746
"color": "White",
4847
"gender": "male",
4948
"breed": "Persian",
5049
}
51-
return &openapi3.Example{
50+
return &Example{
5251
Summary: "An example of a cat",
5352
Value: value,
5453
}

openapi3/extension_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
package openapi3_test
1+
package openapi3
22

33
import (
4+
"testing"
5+
46
"github.com/getkin/kin-openapi/jsoninfo"
5-
"github.com/getkin/kin-openapi/openapi3"
67
"github.com/stretchr/testify/assert"
7-
"testing"
88
)
99

1010
func TestExtensionProps_EncodeWith(t *testing.T) {
1111
t.Run("successfully encoded", func(t *testing.T) {
1212
encoder := jsoninfo.NewObjectEncoder()
13-
var extensionProps = openapi3.ExtensionProps{
13+
var extensionProps = ExtensionProps{
1414
Extensions: map[string]interface{}{
1515
"field1": "value1",
1616
},
@@ -36,7 +36,7 @@ func TestExtensionProps_DecodeWith(t *testing.T) {
3636
t.Run("successfully decode all the fields", func(t *testing.T) {
3737
decoder, err := jsoninfo.NewObjectDecoder(data)
3838
assert.Nil(t, err)
39-
var extensionProps = &openapi3.ExtensionProps{
39+
var extensionProps = &ExtensionProps{
4040
Extensions: map[string]interface{}{
4141
"field1": "value1",
4242
"field2": "value1",
@@ -58,7 +58,7 @@ func TestExtensionProps_DecodeWith(t *testing.T) {
5858
t.Run("successfully decode some of the fields", func(t *testing.T) {
5959
decoder, err := jsoninfo.NewObjectDecoder(data)
6060
assert.Nil(t, err)
61-
var extensionProps = &openapi3.ExtensionProps{
61+
var extensionProps = &ExtensionProps{
6262
Extensions: map[string]interface{}{
6363
"field1": "value1",
6464
"field2": "value2",
@@ -79,7 +79,7 @@ func TestExtensionProps_DecodeWith(t *testing.T) {
7979
decoder, err := jsoninfo.NewObjectDecoder(data)
8080
assert.Nil(t, err)
8181

82-
var extensionProps = &openapi3.ExtensionProps{
82+
var extensionProps = &ExtensionProps{
8383
Extensions: map[string]interface{}{
8484
"field1": "value1",
8585
"field2": "value2",

openapi3/media_type_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package openapi3_test
1+
package openapi3
22

33
import (
44
"context"
55
"encoding/json"
66
"testing"
77

8-
"github.com/getkin/kin-openapi/openapi3"
98
"github.com/stretchr/testify/require"
109
)
1110

@@ -16,13 +15,13 @@ func TestMediaTypeJSON(t *testing.T) {
1615
require.NotEmpty(t, data)
1716

1817
t.Log("Unmarshal *openapi3.MediaType from JSON")
19-
docA := &openapi3.MediaType{}
18+
docA := &MediaType{}
2019
err = json.Unmarshal(mediaTypeJSON, &docA)
2120
require.NoError(t, err)
2221
require.NotEmpty(t, data)
2322

2423
t.Log("Validate *openapi3.MediaType")
25-
err = docA.Validate(context.TODO())
24+
err = docA.Validate(context.Background())
2625
require.NoError(t, err)
2726

2827
t.Log("Ensure representations match")
@@ -52,22 +51,22 @@ var mediaTypeJSON = []byte(`
5251
}
5352
`)
5453

55-
func mediaType() *openapi3.MediaType {
54+
func mediaType() *MediaType {
5655
example := map[string]string{"name": "Some example"}
57-
return &openapi3.MediaType{
58-
Schema: &openapi3.SchemaRef{
59-
Value: &openapi3.Schema{
56+
return &MediaType{
57+
Schema: &SchemaRef{
58+
Value: &Schema{
6059
Description: "Some schema",
6160
},
6261
},
63-
Encoding: map[string]*openapi3.Encoding{
62+
Encoding: map[string]*Encoding{
6463
"someEncoding": {
6564
ContentType: "application/xml; charset=utf-8",
6665
},
6766
},
68-
Examples: map[string]*openapi3.ExampleRef{
67+
Examples: map[string]*ExampleRef{
6968
"someExample": {
70-
Value: openapi3.NewExample(example),
69+
Value: NewExample(example),
7170
},
7271
},
7372
}

0 commit comments

Comments
 (0)