Skip to content

Commit 98f80ab

Browse files
authored
chore: minor option naming refactor (#1660)
This PR renames two of the member fields of the option struct more descriptive names.
1 parent aa2602f commit 98f80ab

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

internal/gengapic/custom_operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type customOp struct {
3333

3434
// isCustomOp determines if the given method should return a custom operation wrapper.
3535
func (g *generator) isCustomOp(m *descriptorpb.MethodDescriptorProto, info *httpInfo) bool {
36-
return g.opts.diregapic && // Generator in DIREGAPIC mode.
36+
return g.opts.generateAsDIREGAPIC && // Generator in DIREGAPIC mode.
3737
g.aux.customOp != nil && // API Defines a custom operation.
3838
m.GetOutputType() == g.customOpProtoName() && // Method returns the custom operation.
3939
m.GetName() != "Wait" && // Method is not a Wait (uses POST).

internal/gengapic/example_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ func TestExample(t *testing.T) {
246246
{
247247
tstName: "custom_op_example",
248248
options: options{
249-
pkgName: "Bar",
250-
transports: []transport{rest},
251-
diregapic: true,
249+
pkgName: "Bar",
250+
transports: []transport{rest},
251+
generateAsDIREGAPIC: true,
252252
},
253253
imports: map[pbinfo.ImportSpec]bool{
254254
{Path: "context"}: true,
@@ -263,7 +263,7 @@ func TestExample(t *testing.T) {
263263
g.reset()
264264
g.opts = &tst.options
265265
g.mixins = mix
266-
if tst.options.diregapic {
266+
if tst.options.generateAsDIREGAPIC {
267267
g.mixins = nil
268268
}
269269
g.aux.customOp = tst.op
@@ -281,7 +281,7 @@ func TestExample(t *testing.T) {
281281

282282
g.opts = &tst.options
283283
g.mixins = mix
284-
if tst.options.diregapic {
284+
if tst.options.generateAsDIREGAPIC {
285285
g.mixins = nil
286286
}
287287
g.aux.customOp = tst.op

internal/gengapic/gengapic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func gen(genReq *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGeneratorResponse
8585

8686
protoPkg := g.descInfo.ParentFile[genServs[0]].GetPackage()
8787

88-
if op, ok := g.descInfo.Type[fmt.Sprintf(".%s.Operation", protoPkg)]; g.opts.diregapic && ok {
88+
if op, ok := g.descInfo.Type[fmt.Sprintf(".%s.Operation", protoPkg)]; g.opts.generateAsDIREGAPIC && ok {
8989
g.aux.customOp = &customOp{
9090
message: op.(*descriptorpb.DescriptorProto),
9191
handles: []*descriptorpb.ServiceDescriptorProto{},
@@ -164,7 +164,7 @@ func gen(genReq *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGeneratorResponse
164164
Content: proto.String(g.pt.String()),
165165
})
166166

167-
if g.opts.metadata {
167+
if g.opts.generateGAPICMetadata {
168168
g.reset()
169169
g.genGapicMetadataFile()
170170
g.resp.File = append(g.resp.File, &pluginpb.CodeGeneratorResponse_File{

internal/gengapic/gengapic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ func TestReturnType(t *testing.T) {
12341234
},
12351235
},
12361236
opts: &options{
1237-
diregapic: true,
1237+
generateAsDIREGAPIC: true,
12381238
},
12391239
descInfo: pbinfo.Info{
12401240
ParentFile: map[protoreflect.ProtoMessage]*descriptorpb.FileDescriptorProto{

internal/gengapic/genrest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ func (g *generator) protoJSONMarshaler() {
11891189
// enum. However, since they are synthetic protos, the enum numbers likely
11901190
// do not match the internal proto enum value, so we do not want to send
11911191
// any enums as numbers with DIREGAPIC clients.
1192-
if g.opts.diregapic {
1192+
if g.opts.generateAsDIREGAPIC {
11931193
marshalOpts = "AllowPartial: true"
11941194
}
11951195
g.pt.Printf("m := protojson.MarshalOptions{%s}", marshalOpts)

internal/gengapic/genrest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ func TestGenRestMethod(t *testing.T) {
753753
{
754754
name: "custom_op",
755755
method: opRPC,
756-
options: &options{diregapic: true},
756+
options: &options{generateAsDIREGAPIC: true},
757757
imports: map[pbinfo.ImportSpec]bool{
758758
{Path: "google.golang.org/protobuf/encoding/protojson"}: true,
759759
{Path: "net/url"}: true,

internal/gengapic/options.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var DeprecatedArgs map[string]error = map[string]error{
4242

4343
// SupportedBooleanArgs expose boolean plugin arguments (presence enables option).
4444
var SupportedBooleanArgs map[string]func() configOption = map[string]func() configOption{
45-
"metadata": enableGAPICMetadata,
45+
"metadata": generateGAPICMetadata,
4646
"diregapic": generateAsDIREGAPIC,
4747
"rest-numeric-enums": enableRESTNumericEnums,
4848
"omit-snippets": enableOmitSnippets,
@@ -82,12 +82,12 @@ type options struct {
8282
outDir string
8383

8484
// Should GAPIC metadata be generated
85-
// TODO: rename this in a subsequent refactor
86-
metadata bool
85+
generateGAPICMetadata bool
8786

88-
// Are the input artifacts from a DIREGAPIC source
89-
// TODO: rename this in a subsequent refactor
90-
diregapic bool
87+
// Should the generator respect DIREGAPIC limitations
88+
// If the input artifacts are synthetic (e.g. compiled from another IDL source such as a discovery document) then
89+
// some protobuf-behaviors should not be relied upon.
90+
generateAsDIREGAPIC bool
9191

9292
// Should the generator code generator numeric enums for REST calls
9393
// TODO: rename this in a subsquent refactor
@@ -209,7 +209,7 @@ func validateAndNormalizeOptions(cfg *options) error {
209209
}
210210

211211
// REST enums are not supported by DIREGAPIC.
212-
if cfg.diregapic && cfg.restNumericEnum {
212+
if cfg.generateAsDIREGAPIC && cfg.restNumericEnum {
213213
return errors.New("incompatible features: diregapic and rest numeric enums")
214214
}
215215

@@ -249,10 +249,10 @@ func withGoGAPICPackage(s string) configOption {
249249
}
250250
}
251251

252-
// enableGAPICMetadata enables generation of GAPIC metadata.
253-
func enableGAPICMetadata() configOption {
252+
// generateGAPICMetadata enables generation of GAPIC metadata.
253+
func generateGAPICMetadata() configOption {
254254
return func(cfg *options) error {
255-
cfg.metadata = true
255+
cfg.generateGAPICMetadata = true
256256
return nil
257257
}
258258
}
@@ -263,7 +263,7 @@ func enableGAPICMetadata() configOption {
263263
// protos (e.g. compute).
264264
func generateAsDIREGAPIC() configOption {
265265
return func(cfg *options) error {
266-
cfg.diregapic = true
266+
cfg.generateAsDIREGAPIC = true
267267
return nil
268268
}
269269
}

internal/gengapic/options_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ func TestParseOptions(t *testing.T) {
5959
{
6060
param: "metadata,go-gapic-package=path;pkg",
6161
expectedOpts: &options{
62-
transports: []transport{grpc},
63-
pkgPath: "path",
64-
pkgName: "pkg",
65-
outDir: "path",
66-
metadata: true,
62+
transports: []transport{grpc},
63+
pkgPath: "path",
64+
pkgName: "pkg",
65+
outDir: "path",
66+
generateGAPICMetadata: true,
6767
},
6868
},
6969
{
@@ -189,11 +189,11 @@ func TestValidateAndNormalizeOptions(t *testing.T) {
189189
{
190190
description: "conflict diregapic enum",
191191
in: &options{
192-
pkgPath: "path",
193-
pkgName: "name",
194-
outDir: "dir",
195-
diregapic: true,
196-
restNumericEnum: true,
192+
pkgPath: "path",
193+
pkgName: "name",
194+
outDir: "dir",
195+
generateAsDIREGAPIC: true,
196+
restNumericEnum: true,
197197
},
198198
wantErr: true,
199199
},

0 commit comments

Comments
 (0)