Skip to content

Commit c3c39e8

Browse files
committed
monitoring: add special case for MService; revert Service->APIService
In 8a410c2, monitoring/v3 got a new schema (item in field "schemas") named "Service". This meant that when the generator generated the API, the name "Service" was already a named type by the time the generator got to creating the "New" method and corresponding struct. So, the generator picked the next item in the "serviceTypes" list to describe the monitoring service: New() *Service became New() *APIService. This is a breaking change. We don't guarantee backwards compatibility (https://godoc.org/google.golang.org/api#hdr-Versioning_and_Stability), but this API is widely depended upon and worthy of making an exception. This CL introduces some mapping from monitoring's Service field to MService. It re-maps the original doc's type in-place, and then any time a ref is requested with name Service it instead requests MService. Fixes #425. Change-Id: I8869a7e9b08ce7e42a9f38abf9a6d5810065efc0 Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/48591 Reviewed-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chris Broadfoot <cbro@google.com>
1 parent ebb9e39 commit c3c39e8

2 files changed

Lines changed: 172 additions & 157 deletions

File tree

google-api-go-generator/gen.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ func (a *API) Target() string {
407407
// ServiceType returns the name of the type to use for the root API struct
408408
// (typically "Service").
409409
func (a *API) ServiceType() string {
410+
if a.Name == "monitoring" && a.Version == "v3" {
411+
// HACK(deklerk) monitoring:v3 should always use call its overall
412+
// service struct "Service", even though there is a "Service" in its
413+
// schema (we re-map it to MService later).
414+
return "Service"
415+
}
410416
switch a.Name {
411417
case "appengine", "content": // retained for historical compatibility.
412418
return "APIService"
@@ -1175,6 +1181,15 @@ func (s *Schema) GoName() string {
11751181
s.goName = s.api.typeAsGo(s.typ, false)
11761182
} else {
11771183
base := initialCap(s.apiName)
1184+
1185+
// HACK(deklerk) Re-maps monitoring's Service field to MService so
1186+
// that the overall struct for this API can keep its name "Service".
1187+
// This takes care of "Service" the initial "goName" for "Service"
1188+
// refs.
1189+
if s.api.Name == "monitoring" && base == "Service" {
1190+
base = "MService"
1191+
}
1192+
11781193
s.goName = s.api.GetName(base)
11791194
if base == "Service" && s.goName != "Service" {
11801195
// Detect the case where a resource is going to clash with the

0 commit comments

Comments
 (0)