Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle wkt in paged requests #1132

Merged
merged 5 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/gengapic/gengapic.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,15 @@ func (g *generator) isLRO(m *descriptor.MethodDescriptorProto) bool {
return m.GetOutputType() == lroType && g.descInfo.ParentFile[m].GetPackage() != "google.longrunning"
}

func (g *generator) isPaginated(m *descriptor.MethodDescriptorProto) bool {
pf, _, err := g.getPagingFields(m)
if err != nil {
return false
}

return pf != nil
}

func (g *generator) returnType(m *descriptor.MethodDescriptorProto) (string, error) {
outType := g.descInfo.Type[m.GetOutputType()]
outSpec, err := g.descInfo.ImportSpec(outType)
Expand Down
24 changes: 13 additions & 11 deletions internal/gengapic/genrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ func (g *generator) queryParams(m *descriptor.MethodDescriptorProto) map[string]
// where a "leaf" field is a non-message whose top message ancestor is 'm'.
// e.g. for a message like the following
//
// message Mollusc {
// message Squid {
// message Mantle {
// int32 mass_kg = 1;
// }
// Mantle mantle = 1;
// }
// Squid squid = 1;
// }
// message Mollusc {
// message Squid {
// message Mantle {
// int32 mass_kg = 1;
// }
// Mantle mantle = 1;
// }
// Squid squid = 1;
// }
//
// The one entry would be
// "squid.mantle.mass_kg": *descriptor.FieldDescriptorProto...
Expand Down Expand Up @@ -428,9 +428,11 @@ func (g *generator) generateQueryString(m *descriptor.MethodDescriptorProto) {
b.WriteString(fmt.Sprintf("%s, err := protojson.Marshal(req%s)\n", field.GetJsonName(), accessor))
b.WriteString("if err != nil {\n")
if m.GetOutputType() == emptyType {
b.WriteString(fmt.Sprintf(" return err\n"))
b.WriteString(" return err\n")
} else if g.isPaginated(m) {
b.WriteString(" return nil, \"\", err\n")
} else {
b.WriteString(fmt.Sprintf(" return nil, err\n"))
b.WriteString(" return nil, err\n")
}
b.WriteString("}\n")
b.WriteString(fmt.Sprintf("params.Add(%q, string(%s))", lowerFirst(snakeToCamel(path)), field.GetJsonName()))
Expand Down