Skip to content

Commit a2254d9

Browse files
authored
nitpicking: use type openapi3.Schemas (#456)
1 parent fd08c7f commit a2254d9

File tree

7 files changed

+20
-17
lines changed

7 files changed

+20
-17
lines changed

openapi3/loader_issue212_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ components:
8181
expected, err := json.Marshal(&Schema{
8282
Type: "object",
8383
Required: []string{"id", "uri"},
84-
Properties: map[string]*SchemaRef{
84+
Properties: Schemas{
8585
"id": {Value: &Schema{Type: "string"}},
8686
"uri": {Value: &Schema{Type: "string"}},
8787
},

openapi3/loader_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,18 @@ paths:
227227
require.NotNil(t, doc.Paths["/"].Post.RequestBody.Value.Content.Get("application/json").Examples["test"])
228228
}
229229

230-
func createTestServer(handler http.Handler) *httptest.Server {
230+
func createTestServer(t *testing.T, handler http.Handler) *httptest.Server {
231231
ts := httptest.NewUnstartedServer(handler)
232-
l, _ := net.Listen("tcp", addr)
232+
l, err := net.Listen("tcp", addr)
233+
require.NoError(t, err)
233234
ts.Listener.Close()
234235
ts.Listener = l
235236
return ts
236237
}
237238

238239
func TestLoadFromRemoteURL(t *testing.T) {
239-
240240
fs := http.FileServer(http.Dir("testdata"))
241-
ts := createTestServer(fs)
241+
ts := createTestServer(t, fs)
242242
ts.Start()
243243
defer ts.Close()
244244

@@ -351,7 +351,7 @@ func TestLoadFromDataWithExternalRequestResponseHeaderRemoteRef(t *testing.T) {
351351
}`)
352352

353353
fs := http.FileServer(http.Dir("testdata"))
354-
ts := createTestServer(fs)
354+
ts := createTestServer(t, fs)
355355
ts.Start()
356356
defer ts.Close()
357357

openapi3/schema.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func NewArraySchema() *Schema {
372372
func NewObjectSchema() *Schema {
373373
return &Schema{
374374
Type: TypeObject,
375-
Properties: make(map[string]*SchemaRef),
375+
Properties: make(Schemas),
376376
}
377377
}
378378

@@ -493,15 +493,15 @@ func (schema *Schema) WithProperty(name string, propertySchema *Schema) *Schema
493493
func (schema *Schema) WithPropertyRef(name string, ref *SchemaRef) *Schema {
494494
properties := schema.Properties
495495
if properties == nil {
496-
properties = make(map[string]*SchemaRef)
496+
properties = make(Schemas)
497497
schema.Properties = properties
498498
}
499499
properties[name] = ref
500500
return schema
501501
}
502502

503503
func (schema *Schema) WithProperties(properties map[string]*Schema) *Schema {
504-
result := make(map[string]*SchemaRef, len(properties))
504+
result := make(Schemas, len(properties))
505505
for k, v := range properties {
506506
result[k] = &SchemaRef{
507507
Value: v,

openapi3/schema_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ var schemaExamples = []schemaExample{
389389
UniqueItems: true,
390390
Items: (&Schema{
391391
Type: "object",
392-
Properties: map[string]*SchemaRef{
392+
Properties: Schemas{
393393
"key1": NewFloat64Schema().NewRef(),
394394
},
395395
}).NewRef(),
@@ -446,7 +446,7 @@ var schemaExamples = []schemaExample{
446446
UniqueItems: true,
447447
Items: (&Schema{
448448
Type: "object",
449-
Properties: map[string]*SchemaRef{
449+
Properties: Schemas{
450450
"key1": (&Schema{
451451
Type: "array",
452452
UniqueItems: true,
@@ -579,7 +579,7 @@ var schemaExamples = []schemaExample{
579579
UniqueItems: true,
580580
Items: (&Schema{
581581
Type: "object",
582-
Properties: map[string]*SchemaRef{
582+
Properties: Schemas{
583583
"key1": NewFloat64Schema().NewRef(),
584584
},
585585
}).NewRef(),
@@ -678,7 +678,7 @@ var schemaExamples = []schemaExample{
678678
Schema: &Schema{
679679
Type: "object",
680680
MaxProps: Uint64Ptr(2),
681-
Properties: map[string]*SchemaRef{
681+
Properties: Schemas{
682682
"numberProperty": NewFloat64Schema().NewRef(),
683683
},
684684
},

openapi3filter/req_resp_decoder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ func decodeStyledParameter(param *openapi3.Parameter, input *RequestValidationIn
244244
}
245245

246246
func decodeValue(dec valueDecoder, param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef, required bool) (interface{}, error) {
247-
var decodeFn func(param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef) (interface{}, error)
248-
249247
if len(schema.Value.AllOf) > 0 {
250248
var value interface{}
251249
var err error
@@ -298,6 +296,7 @@ func decodeValue(dec valueDecoder, param string, sm *openapi3.SerializationMetho
298296
}
299297

300298
if schema.Value.Type != "" {
299+
var decodeFn func(param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef) (interface{}, error)
301300
switch schema.Value.Type {
302301
case "array":
303302
decodeFn = func(param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef) (interface{}, error) {

openapi3filter/validation_error_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ type validationTest struct {
5656
}
5757

5858
func getValidationTests(t *testing.T) []*validationTest {
59-
badHost, _ := http.NewRequest(http.MethodGet, "http://unknown-host.com/v2/pet", nil)
59+
badHost, err := http.NewRequest(http.MethodGet, "http://unknown-host.com/v2/pet", nil)
60+
require.NoError(t, err)
6061
badPath := newPetstoreRequest(t, http.MethodGet, "/watdis", nil)
6162
badMethod := newPetstoreRequest(t, http.MethodTrace, "/pet", nil)
6263

routers/legacy/router.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ func (router *Router) FindRoute(req *http.Request) (*routers.Route, map[string]s
125125
}
126126
}
127127
pathParams = make(map[string]string, 8)
128-
paramNames, _ := server.ParameterNames()
128+
paramNames, err := server.ParameterNames()
129+
if err != nil {
130+
return nil, nil, err
131+
}
129132
for i, value := range paramValues {
130133
name := paramNames[i]
131134
pathParams[name] = value

0 commit comments

Comments
 (0)