Skip to content
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
6 changes: 3 additions & 3 deletions internal/gengapic/auxiliary.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func (g *generator) genAuxFile() error {
return err
}

g.commit(filepath.Join(g.opts.outDir, "auxiliary.go"), g.opts.pkgName)
g.commit(filepath.Join(g.cfg.outDir, "auxiliary.go"), g.cfg.pkgName)
g.reset()

g.genIteratorsGo123()
g.commitWithBuildTag(filepath.Join(g.opts.outDir, "auxiliary_go123.go"), g.opts.pkgName, "go1.23")
g.commitWithBuildTag(filepath.Join(g.cfg.outDir, "auxiliary_go123.go"), g.cfg.pkgName, "go1.23")
g.reset()

return nil
Expand Down Expand Up @@ -251,7 +251,7 @@ func (g *generator) maybeAddOperationWrapper(m *descriptorpb.MethodDescriptorPro
// this.
func (g *generator) genOperationWrapperType(ow operationWrapper) error {
p := g.pt.Printf
hasREST := containsTransport(g.opts.transports, rest)
hasREST := containsTransport(g.cfg.transports, rest)
isEmpty := ow.responseName == emptyValue

// Response Go type resolution.
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/auxiliary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func TestGenOperations(t *testing.T) {
ParentElement: make(map[pbinfo.ProtoType]pbinfo.ProtoType),
},
imports: make(map[pbinfo.ImportSpec]bool),
opts: &options{transports: []transport{grpc, rest}},
cfg: &generatorConfig{transports: []transport{grpc, rest}},
}

wantImports := map[pbinfo.ImportSpec]bool{
Expand Down
4 changes: 2 additions & 2 deletions internal/gengapic/client_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (g *generator) clientOptions(serv *descriptorpb.ServiceDescriptorProto, ser
g.imports[pbinfo.ImportSpec{Name: "gax", Path: "github.com/googleapis/gax-go/v2"}] = true
}

for _, v := range g.opts.transports {
for _, v := range g.cfg.transports {
switch v {
case grpc:
if err := g.grpcClientOptions(serv, servName); err != nil {
Expand Down Expand Up @@ -396,7 +396,7 @@ func (g *generator) makeClients(serv *descriptorpb.ServiceDescriptorProto, servN
}
g.clientInit(serv, servName, hasLRO)

for _, v := range g.opts.transports {
for _, v := range g.cfg.transports {
switch v {
case grpc:
g.grpcClientInit(serv, servName, imp, hasLRO)
Expand Down
26 changes: 15 additions & 11 deletions internal/gengapic/client_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,19 @@ func TestClientOpt(t *testing.T) {
"google.cloud.location.Locations": locationMethods(),
"google.iam.v1.IAMPolicy": iamPolicyMethods(),
},
serviceConfig: &serviceconfig.Service{
Name: "showcase.googleapis.com",
Apis: []*apipb.Api{
{Name: "foo.bar.Baz"},
{Name: "google.iam.v1.IAMPolicy"},
{Name: "google.cloud.location.Locations"},
{Name: "google.longrunning.Operations"},

cfg: &generatorConfig{
transports: []transport{grpc, rest},
APIServiceConfig: &serviceconfig.Service{
Name: "showcase.googleapis.com",
Apis: []*apipb.Api{
{Name: "foo.bar.Baz"},
{Name: "google.iam.v1.IAMPolicy"},
{Name: "google.cloud.location.Locations"},
{Name: "google.longrunning.Operations"},
},
},
},
opts: &options{transports: []transport{grpc, rest}},
grpcConf: grpcConf,
gRPCServiceConfig: grpcConf},
}

serv := &descriptorpb.ServiceDescriptorProto{
Expand Down Expand Up @@ -270,6 +272,7 @@ func TestServiceDoc(t *testing.T) {

var g generator
g.comments = make(map[protoiface.MessageV1]string)
g.cfg = &generatorConfig{}

for _, tst := range []struct {
in, want string
Expand Down Expand Up @@ -573,14 +576,15 @@ func TestClientInit(t *testing.T) {
tst.serv.GetMethod()[0]: "Does some stuff.",
}
g.mixins = tst.mixins
g.serviceConfig = &serviceconfig.Service{
g.cfg.APIServiceConfig = &serviceconfig.Service{
Apis: []*apipb.Api{
{Name: "foo.bar.Baz"},
{Name: "google.iam.v1.IAMPolicy"},
{Name: "google.cloud.location.Locations"},
{Name: "google.longrunning.Operations"},
},
}

g.aux.customOp = &customOp{
message: cop,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/gengapic/custom_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type customOp struct {

// isCustomOp determines if the given method should return a custom operation wrapper.
func (g *generator) isCustomOp(m *descriptorpb.MethodDescriptorProto, info *httpInfo) bool {
return g.opts.generateAsDIREGAPIC && // Generator in DIREGAPIC mode.
return g.cfg.generateAsDIREGAPIC && // Generator in DIREGAPIC mode.
g.aux.customOp != nil && // API Defines a custom operation.
m.GetOutputType() == g.customOpProtoName() && // Method returns the custom operation.
m.GetName() != "Wait" && // Method is not a Wait (uses POST).
Expand Down Expand Up @@ -70,7 +70,7 @@ func (g *generator) customOpPointerType() (string, error) {
// operation wrapper type with the Go identifier for a variable that is the
// proto-defined operation type.
func (g *generator) customOpInit(rspVar, reqVar, opVar string, req *descriptorpb.DescriptorProto, s *descriptorpb.ServiceDescriptorProto) {
h := handleName(s.GetName(), g.opts.pkgName)
h := handleName(s.GetName(), g.cfg.pkgName)
opName := g.aux.customOp.message.GetName()
pt := g.pt.Printf

Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/custom_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestCustomOpInit(t *testing.T) {
},
},
},
opts: &options{pkgName: "bar"},
cfg: &generatorConfig{pkgName: "bar"},
}
g.customOpInit("foo", "req", "op", req, opServ)
txtdiff.Diff(t, g.pt.String(), filepath.Join("testdata", "custom_op_init_helper.want"))
Expand Down
18 changes: 9 additions & 9 deletions internal/gengapic/doc_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (g *generator) genDocFile(year int, services []*descriptorpb.ServiceDescrip
p("")

if g.apiName != "" {
p("// Package %s is an auto-generated package for the ", g.opts.pkgName)
p("// Package %s is an auto-generated package for the ", g.cfg.pkgName)
p("// %s.", g.apiName)
}

if g.serviceConfig != nil && g.serviceConfig.GetDocumentation() != nil {
summary := g.serviceConfig.GetDocumentation().GetSummary()
if g.cfg.APIServiceConfig != nil && g.cfg.APIServiceConfig.GetDocumentation() != nil {
summary := g.cfg.APIServiceConfig.GetDocumentation().GetSummary()
summary = mdPlain(summary)
wrapped := wrapString(summary, 75)

Expand All @@ -59,7 +59,7 @@ func (g *generator) genDocFile(year int, services []*descriptorpb.ServiceDescrip
}
}

switch g.opts.relLvl {
switch g.cfg.relLvl {
case alpha:
p("//")
p("// NOTE: This package is in alpha. It is not stable, and is likely to change.")
Expand Down Expand Up @@ -92,10 +92,10 @@ func (g *generator) genDocFile(year int, services []*descriptorpb.ServiceDescrip
// Code block for client creation
exampleService := services[0]
override := g.getServiceNameOverride(exampleService)
servName := pbinfo.ReduceServNameWithOverride(exampleService.GetName(), g.opts.pkgName, override)
servName := pbinfo.ReduceServNameWithOverride(exampleService.GetName(), g.cfg.pkgName, override)
tmpClient := g.pt
g.pt = printer.P{}
g.exampleInitClientWithOpts(g.opts.pkgName, servName, true)
g.exampleInitClientWithOpts(g.cfg.pkgName, servName, true)
snipClient := g.pt.String()
g.pt = tmpClient
g.codesnippet(snipClient)
Expand All @@ -112,7 +112,7 @@ func (g *generator) genDocFile(year int, services []*descriptorpb.ServiceDescrip
// Code block for client using the first method of the service
tmpMethod := g.pt
g.pt = printer.P{}
g.exampleMethodBodyWithOpts(g.opts.pkgName, servName, exampleService.GetMethod()[0], true)
g.exampleMethodBodyWithOpts(g.cfg.pkgName, servName, exampleService.GetMethod()[0], true)
snipMethod := g.pt.String()
g.pt = tmpMethod
g.codesnippet(snipMethod)
Expand All @@ -131,7 +131,7 @@ func (g *generator) genDocFile(year int, services []*descriptorpb.ServiceDescrip
p("// [Testing against Client Libraries]: https://pkg.go.dev/cloud.google.com/go#hdr-Testing")
p("// [Debugging Client Libraries]: https://pkg.go.dev/cloud.google.com/go#hdr-Debugging")
p("// [Inspecting errors]: https://pkg.go.dev/cloud.google.com/go#hdr-Inspecting_errors")
p("package %s // import %q", g.opts.pkgName, g.opts.pkgPath)
p("package %s // import %q", g.cfg.pkgName, g.cfg.pkgPath)
p("")
}

Expand Down Expand Up @@ -202,7 +202,7 @@ func (g *generator) apiVersionSection(services []*descriptorpb.ServiceDescriptor
// Construct the reduced/overridden service name used for client
// type name derivation.
override := g.getServiceNameOverride(s)
sn := pbinfo.ReduceServNameWithOverride(n, g.opts.pkgName, override)
sn := pbinfo.ReduceServNameWithOverride(n, g.cfg.pkgName, override)
ct := fmt.Sprintf("%sClient", sn)

// Use the raw proto service name in the tuple to associate it with
Expand Down
52 changes: 26 additions & 26 deletions internal/gengapic/doc_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (

func TestDocFile(t *testing.T) {
g := generator{
apiName: sample.ServiceTitle,
serviceConfig: sample.ServiceConfig(),
imports: map[pbinfo.ImportSpec]bool{},
opts: &options{
pkgPath: sample.GoPackagePath,
pkgName: sample.GoPackageName,
transports: []transport{grpc, rest},
apiName: sample.ServiceTitle,
imports: map[pbinfo.ImportSpec]bool{},
cfg: &generatorConfig{
pkgPath: sample.GoPackagePath,
pkgName: sample.GoPackageName,
transports: []transport{grpc, rest},
APIServiceConfig: sample.ServiceConfig(),
},
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func TestDocFile(t *testing.T) {
},
} {
t.Run(tst.want, func(t *testing.T) {
g.opts.relLvl = tst.relLvl
g.cfg.relLvl = tst.relLvl
g.genDocFile(sample.Year, []*descriptorpb.ServiceDescriptorProto{serv})
txtdiff.Diff(t, g.pt.String(), tst.want)
g.reset()
Expand All @@ -77,13 +77,13 @@ func TestDocFile(t *testing.T) {

func TestDocFile_APIVersionSection(t *testing.T) {
g := generator{
apiName: sample.ServiceTitle,
serviceConfig: sample.ServiceConfig(),
imports: map[pbinfo.ImportSpec]bool{},
opts: &options{
pkgPath: sample.GoPackagePath,
pkgName: sample.GoPackageName,
transports: []transport{grpc, rest},
apiName: sample.ServiceTitle,
imports: map[pbinfo.ImportSpec]bool{},
cfg: &generatorConfig{
pkgPath: sample.GoPackagePath,
pkgName: sample.GoPackageName,
transports: []transport{grpc, rest},
APIServiceConfig: sample.ServiceConfig(),
},
}

Expand All @@ -110,13 +110,13 @@ func TestDocFile_APIVersionSection(t *testing.T) {

func TestDocFileEmptyService(t *testing.T) {
g := generator{
apiName: sample.ServiceTitle,
imports: map[pbinfo.ImportSpec]bool{},
serviceConfig: sample.ServiceConfig(),
opts: &options{
pkgPath: sample.GoPackagePath,
pkgName: sample.GoPackageName,
transports: []transport{grpc, rest},
apiName: sample.ServiceTitle,
imports: map[pbinfo.ImportSpec]bool{},
cfg: &generatorConfig{
pkgPath: sample.GoPackagePath,
pkgName: sample.GoPackageName,
transports: []transport{grpc, rest},
APIServiceConfig: sample.ServiceConfig(),
},
}
inputType := sample.InputType(sample.CreateRequest)
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestDocFileEmptyService(t *testing.T) {
},
} {
t.Run(tst.want, func(t *testing.T) {
g.opts.relLvl = tst.relLvl
g.cfg.relLvl = tst.relLvl
g.genDocFile(sample.Year, []*descriptorpb.ServiceDescriptorProto{serv})
txtdiff.Diff(t, g.pt.String(), tst.want)
g.reset()
Expand All @@ -164,9 +164,9 @@ func TestDocFileEmptyService(t *testing.T) {

func TestApiVersionSection(t *testing.T) {
g := generator{
serviceConfig: sample.ServiceConfig(),
opts: &options{
pkgName: sample.GoPackageName,
cfg: &generatorConfig{
pkgName: sample.GoPackageName,
APIServiceConfig: sample.ServiceConfig(),
},
}

Expand Down
12 changes: 6 additions & 6 deletions internal/gengapic/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func (g *generator) genExampleFile(serv *descriptorpb.ServiceDescriptorProto) error {
pkgName := g.opts.pkgName
pkgName := g.cfg.pkgName
override := g.getServiceNameOverride(serv)
servName := pbinfo.ReduceServNameWithOverride(serv.GetName(), pkgName, override)

Expand All @@ -42,7 +42,7 @@ func (g *generator) genExampleFile(serv *descriptorpb.ServiceDescriptorProto) er
}

func (g *generator) genExampleIteratorFile(serv *descriptorpb.ServiceDescriptorProto) error {
pkgName := g.opts.pkgName
pkgName := g.cfg.pkgName
override := g.getServiceNameOverride(serv)
servName := pbinfo.ReduceServNameWithOverride(serv.GetName(), pkgName, override)
methods := append(serv.GetMethod(), g.getMixinMethods()...)
Expand Down Expand Up @@ -75,7 +75,7 @@ func (g *generator) genExampleIteratorFile(serv *descriptorpb.ServiceDescriptorP
g.imports[inSpec] = true
// Pick the first transport for simplicity. We don't need examples
// of each method for both transports when they have the same surface.
t := g.opts.transports[0]
t := g.cfg.transports[0]
s := servName
if t == rest {
s += "REST"
Expand All @@ -100,7 +100,7 @@ func (g *generator) genExampleIteratorFile(serv *descriptorpb.ServiceDescriptorP

func (g *generator) exampleClientFactory(pkgName, servName string) {
p := g.printf
for _, t := range g.opts.transports {
for _, t := range g.cfg.transports {
s := servName
if t == rest {
s += "REST"
Expand All @@ -125,7 +125,7 @@ func (g *generator) exampleInitClient(pkgName, servName string) {
func (g *generator) exampleInitClientWithOpts(pkgName, servName string, isPackageDoc bool) {
p := g.printf
if isPackageDoc {
p("// go get %s@latest", g.opts.pkgPath)
p("// go get %s@latest", g.cfg.pkgPath)
}
p("ctx := context.Background()")
p("// This snippet has been automatically generated and should be regarded as a code template only.")
Expand Down Expand Up @@ -195,7 +195,7 @@ func (g *generator) exampleMethodBodyWithOpts(pkgName, servName string, m *descr
g.imports[inSpec] = true
// Pick the first transport for simplicity. We don't need examples
// of each method for both transports when they have the same surface.
t := g.opts.transports[0]
t := g.cfg.transports[0]
s := servName
if t == rest {
s += "REST"
Expand Down
Loading
Loading