Skip to content

Commit

Permalink
Merge pull request #392 from Jefftree/patch-2
Browse files Browse the repository at this point in the history
Remove empty error returned from registering OpenAPI
  • Loading branch information
k8s-ci-robot authored May 23, 2023
2 parents 54b630e + 2ff681c commit df37dd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
12 changes: 6 additions & 6 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ func ToProtoBinary(json []byte) ([]byte, error) {
// RegisterOpenAPIVersionedService registers a handler to provide access to provided swagger spec.
//
// Deprecated: use OpenAPIService.RegisterOpenAPIVersionedService instead.
func RegisterOpenAPIVersionedService(spec *spec.Swagger, servePath string, handler common.PathHandler) (*OpenAPIService, error) {
func RegisterOpenAPIVersionedService(spec *spec.Swagger, servePath string, handler common.PathHandler) *OpenAPIService {
o := NewOpenAPIService(spec)
return o, o.RegisterOpenAPIVersionedService(servePath, handler)
o.RegisterOpenAPIVersionedService(servePath, handler)
return o
}

// RegisterOpenAPIVersionedService registers a handler to provide access to provided swagger spec.
func (o *OpenAPIService) RegisterOpenAPIVersionedService(servePath string, handler common.PathHandler) error {
func (o *OpenAPIService) RegisterOpenAPIVersionedService(servePath string, handler common.PathHandler) {
// Mutex protects the cache chain
var mutex sync.Mutex

Expand Down Expand Up @@ -183,8 +184,6 @@ func (o *OpenAPIService) RegisterOpenAPIVersionedService(servePath string, handl
return
}),
))

return nil
}

// BuildAndRegisterOpenAPIVersionedService builds the spec and registers a handler to provide access to it.
Expand All @@ -203,5 +202,6 @@ func BuildAndRegisterOpenAPIVersionedServiceFromRoutes(servePath string, routeCo
return nil, err
}
o := NewOpenAPIService(spec)
return o, o.RegisterOpenAPIVersionedService(servePath, handler)
o.RegisterOpenAPIVersionedService(servePath, handler)
return o, nil
}
12 changes: 3 additions & 9 deletions pkg/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ func TestRegisterOpenAPIVersionedService(t *testing.T) {

mux := http.NewServeMux()
o := NewOpenAPIService(&s)
if err := o.RegisterOpenAPIVersionedService("/openapi/v2", mux); err != nil {
t.Errorf("Unexpected error in register OpenAPI versioned service: %v", err)
}
o.RegisterOpenAPIVersionedService("/openapi/v2", mux)
server := httptest.NewServer(mux)
defer server.Close()
client := server.Client()
Expand Down Expand Up @@ -170,9 +168,7 @@ func TestUpdateSpecLazy(t *testing.T) {

mux := http.NewServeMux()
o := NewOpenAPIService(&s)
if err := o.RegisterOpenAPIVersionedService("/openapi/v2", mux); err != nil {
t.Errorf("Unexpected error in register OpenAPI versioned service: %v", err)
}
o.RegisterOpenAPIVersionedService("/openapi/v2", mux)
server := httptest.NewServer(mux)
defer server.Close()

Expand Down Expand Up @@ -221,9 +217,7 @@ func TestConcurrentReadStaleCache(t *testing.T) {

mux := http.NewServeMux()
o := NewOpenAPIService(&s)
if err := o.RegisterOpenAPIVersionedService("/openapi/v2", mux); err != nil {
t.Errorf("Unexpected error in register OpenAPI versioned service: %v", err)
}
o.RegisterOpenAPIVersionedService("/openapi/v2", mux)
server := httptest.NewServer(mux)
defer server.Close()

Expand Down

0 comments on commit df37dd0

Please sign in to comment.