From a6cbaab5b24039d05c280c699daadae3be26d9e2 Mon Sep 17 00:00:00 2001 From: Michal Fudala Date: Mon, 15 Jul 2024 20:09:57 +0200 Subject: [PATCH] add handler for new discovery endpoint so that CLI tools like bq work (#8) Related: - Issue in the upstream repo: https://github.com/goccy/bigquery-emulator/issues/290 - PR in the upstream repo: https://github.com/goccy/bigquery-emulator/pull/338 --- server/handler.go | 5 +++-- server/server.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/handler.go b/server/handler.go index 2c7415142..87641dfe8 100644 --- a/server/handler.go +++ b/server/handler.go @@ -54,8 +54,9 @@ func encodeResponse(ctx context.Context, w http.ResponseWriter, response interfa } const ( - discoveryAPIEndpoint = "/discovery/v1/apis/bigquery/v2/rest" - uploadAPIEndpoint = "/upload/bigquery/v2/projects/{projectId}/jobs" + discoveryAPIEndpoint = "/discovery/v1/apis/bigquery/v2/rest" + newDiscoveryAPIEndpoint = "/$discovery/rest" + uploadAPIEndpoint = "/upload/bigquery/v2/projects/{projectId}/jobs" ) //go:embed resources/discovery.json diff --git a/server/server.go b/server/server.go index bfa2a4791..94c73ffe7 100644 --- a/server/server.go +++ b/server/server.go @@ -79,6 +79,7 @@ func New(storage Storage) (*Server, error) { r.Handle(fmt.Sprintf("/bigquery/v2%s", handler.Path), handler.Handler).Methods(handler.HTTPMethod) } r.Handle(discoveryAPIEndpoint, newDiscoveryHandler(server)).Methods("GET") + r.Handle(newDiscoveryAPIEndpoint, newDiscoveryHandler(server)).Methods("GET") r.Handle(uploadAPIEndpoint, &uploadHandler{}).Methods("POST") r.Handle(uploadAPIEndpoint, &uploadContentHandler{}).Methods("PUT") r.PathPrefix("/").Handler(&defaultHandler{})