Skip to content

Commit

Permalink
fix: handle wkt in paged requests (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Sep 13, 2022
1 parent 9897e82 commit 0c23c8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
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

0 comments on commit 0c23c8d

Please sign in to comment.