From 14424c4f61bb69cb59d437b99d3da780bb257400 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 21 Aug 2024 17:38:48 -0600 Subject: [PATCH] fix(gen): change HttpBody.Data from string to any for monitoring:v1 fixes: 2304 --- google-api-go-generator/gen.go | 8 ++++++++ monitoring/v1/monitoring-gen.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/google-api-go-generator/gen.go b/google-api-go-generator/gen.go index b22c2268d52..1fc1a3f2d9d 100644 --- a/google-api-go-generator/gen.go +++ b/google-api-go-generator/gen.go @@ -1587,6 +1587,14 @@ func (s *Schema) writeSchemaStruct(api *API) { typ = "*" + typ } + // HACK(chrisdsmith) Hardcodes HttpBody.Data to the Go type "any" only + // for monitoring:v1 in order to avoid errors with JSON objects in the responses. + // (json: cannot unmarshal object into Go struct field HttpBody.data of type string) + // See https://github.com/googleapis/google-api-go-client/issues/2304 + if s.api.Name == "monitoring" && s.api.Version == "v1" && s.GoName() == "HttpBody" && pname == "Data" { + typ = "any" + } + s.api.pn(" %s %s `json:\"%s,omitempty%s\"`", pname, typ, p.p.Name, extraOpt) if firstFieldName == "" { firstFieldName = pname diff --git a/monitoring/v1/monitoring-gen.go b/monitoring/v1/monitoring-gen.go index a4fa89a5310..44e2c63cb29 100644 --- a/monitoring/v1/monitoring-gen.go +++ b/monitoring/v1/monitoring-gen.go @@ -1411,7 +1411,7 @@ type HttpBody struct { // of the body. ContentType string `json:"contentType,omitempty"` // Data: The HTTP request/response body as raw binary. - Data string `json:"data,omitempty"` + Data any `json:"data,omitempty"` // Extensions: Application specific response metadata. Must be set in the first // response for streaming APIs. Extensions []googleapi.RawMessage `json:"extensions,omitempty"`