Skip to content

Commit

Permalink
nitpicking: use type openapi3.Schemas (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Dec 3, 2021
1 parent fd08c7f commit a2254d9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion openapi3/loader_issue212_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ components:
expected, err := json.Marshal(&Schema{
Type: "object",
Required: []string{"id", "uri"},
Properties: map[string]*SchemaRef{
Properties: Schemas{
"id": {Value: &Schema{Type: "string"}},
"uri": {Value: &Schema{Type: "string"}},
},
Expand Down
10 changes: 5 additions & 5 deletions openapi3/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,18 @@ paths:
require.NotNil(t, doc.Paths["/"].Post.RequestBody.Value.Content.Get("application/json").Examples["test"])
}

func createTestServer(handler http.Handler) *httptest.Server {
func createTestServer(t *testing.T, handler http.Handler) *httptest.Server {
ts := httptest.NewUnstartedServer(handler)
l, _ := net.Listen("tcp", addr)
l, err := net.Listen("tcp", addr)
require.NoError(t, err)
ts.Listener.Close()
ts.Listener = l
return ts
}

func TestLoadFromRemoteURL(t *testing.T) {

fs := http.FileServer(http.Dir("testdata"))
ts := createTestServer(fs)
ts := createTestServer(t, fs)
ts.Start()
defer ts.Close()

Expand Down Expand Up @@ -351,7 +351,7 @@ func TestLoadFromDataWithExternalRequestResponseHeaderRemoteRef(t *testing.T) {
}`)

fs := http.FileServer(http.Dir("testdata"))
ts := createTestServer(fs)
ts := createTestServer(t, fs)
ts.Start()
defer ts.Close()

Expand Down
6 changes: 3 additions & 3 deletions openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func NewArraySchema() *Schema {
func NewObjectSchema() *Schema {
return &Schema{
Type: TypeObject,
Properties: make(map[string]*SchemaRef),
Properties: make(Schemas),
}
}

Expand Down Expand Up @@ -493,15 +493,15 @@ func (schema *Schema) WithProperty(name string, propertySchema *Schema) *Schema
func (schema *Schema) WithPropertyRef(name string, ref *SchemaRef) *Schema {
properties := schema.Properties
if properties == nil {
properties = make(map[string]*SchemaRef)
properties = make(Schemas)
schema.Properties = properties
}
properties[name] = ref
return schema
}

func (schema *Schema) WithProperties(properties map[string]*Schema) *Schema {
result := make(map[string]*SchemaRef, len(properties))
result := make(Schemas, len(properties))
for k, v := range properties {
result[k] = &SchemaRef{
Value: v,
Expand Down
8 changes: 4 additions & 4 deletions openapi3/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ var schemaExamples = []schemaExample{
UniqueItems: true,
Items: (&Schema{
Type: "object",
Properties: map[string]*SchemaRef{
Properties: Schemas{
"key1": NewFloat64Schema().NewRef(),
},
}).NewRef(),
Expand Down Expand Up @@ -446,7 +446,7 @@ var schemaExamples = []schemaExample{
UniqueItems: true,
Items: (&Schema{
Type: "object",
Properties: map[string]*SchemaRef{
Properties: Schemas{
"key1": (&Schema{
Type: "array",
UniqueItems: true,
Expand Down Expand Up @@ -579,7 +579,7 @@ var schemaExamples = []schemaExample{
UniqueItems: true,
Items: (&Schema{
Type: "object",
Properties: map[string]*SchemaRef{
Properties: Schemas{
"key1": NewFloat64Schema().NewRef(),
},
}).NewRef(),
Expand Down Expand Up @@ -678,7 +678,7 @@ var schemaExamples = []schemaExample{
Schema: &Schema{
Type: "object",
MaxProps: Uint64Ptr(2),
Properties: map[string]*SchemaRef{
Properties: Schemas{
"numberProperty": NewFloat64Schema().NewRef(),
},
},
Expand Down
3 changes: 1 addition & 2 deletions openapi3filter/req_resp_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ func decodeStyledParameter(param *openapi3.Parameter, input *RequestValidationIn
}

func decodeValue(dec valueDecoder, param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef, required bool) (interface{}, error) {
var decodeFn func(param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef) (interface{}, error)

if len(schema.Value.AllOf) > 0 {
var value interface{}
var err error
Expand Down Expand Up @@ -298,6 +296,7 @@ func decodeValue(dec valueDecoder, param string, sm *openapi3.SerializationMetho
}

if schema.Value.Type != "" {
var decodeFn func(param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef) (interface{}, error)
switch schema.Value.Type {
case "array":
decodeFn = func(param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef) (interface{}, error) {
Expand Down
3 changes: 2 additions & 1 deletion openapi3filter/validation_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ type validationTest struct {
}

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

Expand Down
5 changes: 4 additions & 1 deletion routers/legacy/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ func (router *Router) FindRoute(req *http.Request) (*routers.Route, map[string]s
}
}
pathParams = make(map[string]string, 8)
paramNames, _ := server.ParameterNames()
paramNames, err := server.ParameterNames()
if err != nil {
return nil, nil, err
}
for i, value := range paramValues {
name := paramNames[i]
pathParams[name] = value
Expand Down

0 comments on commit a2254d9

Please sign in to comment.