From 91815a97dd7e86b989b6dd04dbd7e9e0798223f2 Mon Sep 17 00:00:00 2001 From: Jeffrey Ying Date: Tue, 23 May 2023 14:39:09 -0400 Subject: [PATCH 1/4] Remove empty error returned from registering OpenAPI --- pkg/handler/handler.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 37cb96f1b..a2daa5c12 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -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 @@ -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. @@ -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 nil, o } From 8a45532cb37c00a681a8e5bf27243cfe2a58a5b6 Mon Sep 17 00:00:00 2001 From: Jeffrey Ying Date: Tue, 23 May 2023 14:40:38 -0400 Subject: [PATCH 2/4] Fix return typo --- pkg/handler/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index a2daa5c12..3a7acff09 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -203,5 +203,5 @@ func BuildAndRegisterOpenAPIVersionedServiceFromRoutes(servePath string, routeCo } o := NewOpenAPIService(spec) o.RegisterOpenAPIVersionedService(servePath, handler) - return nil, o + return o, nil } From d52469dabda8948367848b6aef788b2521c1a7d7 Mon Sep 17 00:00:00 2001 From: Jeffrey Ying Date: Tue, 23 May 2023 14:42:18 -0400 Subject: [PATCH 3/4] Update tests --- pkg/handler/handler_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/handler/handler_test.go b/pkg/handler/handler_test.go index e10716651..4375099e3 100644 --- a/pkg/handler/handler_test.go +++ b/pkg/handler/handler_test.go @@ -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() From 2ff681c3a2c26b75c06938f41c21263d91699ffe Mon Sep 17 00:00:00 2001 From: Jeffrey Ying Date: Tue, 23 May 2023 14:51:26 -0400 Subject: [PATCH 4/4] Fix CI --- pkg/handler/handler_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/handler/handler_test.go b/pkg/handler/handler_test.go index 4375099e3..56d0d5bee 100644 --- a/pkg/handler/handler_test.go +++ b/pkg/handler/handler_test.go @@ -168,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() @@ -219,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()