Skip to content

Commit fd8e45a

Browse files
authored
chore(internal/config): remove ClientPackageOverride from Go configuration (#4284)
A follow up of #4251, remove `ClientPackageOverride`. In addition, rename `ClientDirectory` to `ClientPackage` because this parameter is used to generate client package, `ClientPackage` is a more suitable name. For #3617
1 parent a470457 commit fd8e45a

11 files changed

Lines changed: 130 additions & 139 deletions

File tree

doc/config-schema.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ This document describes the schema for the librarian.yaml.
120120

121121
| Field | Type | Description |
122122
| :--- | :--- | :--- |
123-
| `client_directory` | string | Is the directory where the client is generated, relative to Library.Output. |
124-
| `client_package_override` | string | Overrides the default package name of the generated client. |
123+
| `client_package` | string | Is the package name of the generated client. |
125124
| `disable_gapic` | bool | Determines whether to generate the GAPIC client. Also known as proto-only client, which does not define a service in the proto files. |
126125
| `enabled_generator_features` | list of string | Provides a mechanism for enabling generator features at the API level. |
127126
| `has_diregapic` | bool | Indicates whether generation uses DIREGAPIC (Discovery REST GAPICs). This is typically false. Used for the GCE (compute) client. |

internal/config/language.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ type GoModule struct {
3030

3131
// GoAPI represents configuration for a single API within a Go module.
3232
type GoAPI struct {
33-
// ClientDirectory is the directory where the client is generated, relative to Library.Output.
34-
ClientDirectory string `yaml:"client_directory,omitempty"`
35-
// ClientPackageOverride overrides the default package name of the generated client.
36-
ClientPackageOverride string `yaml:"client_package_override,omitempty"`
33+
// ClientPackage is the package name of the generated client.
34+
ClientPackage string `yaml:"client_package,omitempty"`
3735
// DisableGAPIC determines whether to generate the GAPIC client.
3836
// Also known as proto-only client, which does not define a service in the proto files.
3937
DisableGAPIC bool `yaml:"disable_gapic,omitempty"`

internal/librarian/golang/generate.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,12 @@ func buildGAPICOpts(apiPath string, library *config.Library, goAPI *config.GoAPI
224224
}
225225

226226
func buildGAPICImportPath(library *config.Library, goAPI *config.GoAPI) string {
227-
clientPkg := goAPI.ClientDirectory
228-
if goAPI.ClientPackageOverride != "" {
229-
clientPkg = goAPI.ClientPackageOverride
230-
}
231227
var modulePathVersion string
232228
if library.Go != nil && library.Go.ModulePathVersion != "" {
233229
modulePathVersion = "/" + library.Go.ModulePathVersion
234230
}
235231
return fmt.Sprintf("cloud.google.com/go/%s%s;%s",
236-
goAPI.ImportPath, modulePathVersion, clientPkg)
232+
goAPI.ImportPath, modulePathVersion, goAPI.ClientPackage)
237233
}
238234

239235
// fixVersioning moves {name}/{version}/* up to {name}/ for versioned modules.

internal/librarian/golang/generate_test.go

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ func TestGenerateLibraries(t *testing.T) {
6060
Go: &config.GoModule{
6161
GoAPIs: []*config.GoAPI{
6262
{
63-
ClientDirectory: "secretmanager",
64-
ImportPath: "secretmanager/apiv1",
65-
Path: "google/cloud/secretmanager/v1",
63+
ClientPackage: "secretmanager",
64+
ImportPath: "secretmanager/apiv1",
65+
Path: "google/cloud/secretmanager/v1",
6666
},
6767
},
6868
},
@@ -80,9 +80,9 @@ func TestGenerateLibraries(t *testing.T) {
8080
Go: &config.GoModule{
8181
GoAPIs: []*config.GoAPI{
8282
{
83-
ClientDirectory: "configdelivery",
84-
ImportPath: "configdelivery/apiv1",
85-
Path: "google/cloud/configdelivery/v1",
83+
ClientPackage: "configdelivery",
84+
ImportPath: "configdelivery/apiv1",
85+
Path: "google/cloud/configdelivery/v1",
8686
},
8787
},
8888
},
@@ -128,9 +128,9 @@ func TestGenerateLibraries_Error(t *testing.T) {
128128
Go: &config.GoModule{
129129
GoAPIs: []*config.GoAPI{
130130
{
131-
ClientDirectory: "non-existent",
132-
ImportPath: "non-existent/apiv1",
133-
Path: "google/cloud/non-existent/v1",
131+
ClientPackage: "non-existent",
132+
ImportPath: "non-existent/apiv1",
133+
Path: "google/cloud/non-existent/v1",
134134
},
135135
},
136136
},
@@ -190,9 +190,9 @@ func TestGenerate(t *testing.T) {
190190
goModule: &config.GoModule{
191191
GoAPIs: []*config.GoAPI{
192192
{
193-
ClientDirectory: "secretmanager",
194-
ImportPath: "secretmanager/apiv1",
195-
Path: "google/cloud/secretmanager/v1",
193+
ClientPackage: "secretmanager",
194+
ImportPath: "secretmanager/apiv1",
195+
Path: "google/cloud/secretmanager/v1",
196196
},
197197
},
198198
},
@@ -214,9 +214,9 @@ func TestGenerate(t *testing.T) {
214214
goModule: &config.GoModule{
215215
GoAPIs: []*config.GoAPI{
216216
{
217-
ClientDirectory: "secretmanager",
218-
ImportPath: "secretmanager/v2/apiv1",
219-
Path: "google/cloud/secretmanager/v1",
217+
ClientPackage: "secretmanager",
218+
ImportPath: "secretmanager/v2/apiv1",
219+
Path: "google/cloud/secretmanager/v1",
220220
},
221221
},
222222
},
@@ -232,9 +232,9 @@ func TestGenerate(t *testing.T) {
232232
DeleteGenerationOutputPaths: []string{"secretmanager/apiv1/secretmanagerpb"},
233233
GoAPIs: []*config.GoAPI{
234234
{
235-
ClientDirectory: "secretmanager",
236-
ImportPath: "secretmanager/apiv1",
237-
Path: "google/cloud/secretmanager/v1",
235+
ClientPackage: "secretmanager",
236+
ImportPath: "secretmanager/apiv1",
237+
Path: "google/cloud/secretmanager/v1",
238238
},
239239
},
240240
},
@@ -252,9 +252,9 @@ func TestGenerate(t *testing.T) {
252252
goModule: &config.GoModule{
253253
GoAPIs: []*config.GoAPI{
254254
{
255-
ClientDirectory: "secretmanager",
256-
ImportPath: "secretmanager/apiv1",
257-
Path: "google/cloud/secretmanager/v1",
255+
ClientPackage: "secretmanager",
256+
ImportPath: "secretmanager/apiv1",
257+
Path: "google/cloud/secretmanager/v1",
258258
},
259259
},
260260
},
@@ -271,9 +271,9 @@ func TestGenerate(t *testing.T) {
271271
goModule: &config.GoModule{
272272
GoAPIs: []*config.GoAPI{
273273
{
274-
ClientDirectory: "secretmanager",
275-
ImportPath: "customdir/apiv1",
276-
Path: "google/cloud/secretmanager/v1",
274+
ClientPackage: "secretmanager",
275+
ImportPath: "customdir/apiv1",
276+
Path: "google/cloud/secretmanager/v1",
277277
},
278278
},
279279
},
@@ -288,10 +288,10 @@ func TestGenerate(t *testing.T) {
288288
goModule: &config.GoModule{
289289
GoAPIs: []*config.GoAPI{
290290
{
291-
ClientDirectory: "secretmanager",
292-
DisableGAPIC: true,
293-
ImportPath: "secretmanager/apiv1",
294-
Path: "google/cloud/secretmanager/v1",
291+
ClientPackage: "secretmanager",
292+
DisableGAPIC: true,
293+
ImportPath: "secretmanager/apiv1",
294+
Path: "google/cloud/secretmanager/v1",
295295
},
296296
},
297297
},
@@ -309,8 +309,8 @@ func TestGenerate(t *testing.T) {
309309
goModule: &config.GoModule{
310310
GoAPIs: []*config.GoAPI{
311311
{
312-
ClientDirectory: "gkehub",
313-
ImportPath: "gkehub/apiv1",
312+
ClientPackage: "gkehub",
313+
ImportPath: "gkehub/apiv1",
314314
NestedProtos: []string{
315315
"configmanagement/configmanagement.proto",
316316
"multiclusteringress/multiclusteringress.proto",
@@ -609,9 +609,9 @@ func TestBuildGAPICImportPath(t *testing.T) {
609609
APIs: []*config.API{{Path: "google/cloud/secretmanager/v1"}},
610610
},
611611
goAPI: &config.GoAPI{
612-
ClientDirectory: "secretmanager",
613-
ImportPath: "secretmanager/apiv1",
614-
Path: "google/cloud/secretmanager/v1",
612+
ClientPackage: "secretmanager",
613+
ImportPath: "secretmanager/apiv1",
614+
Path: "google/cloud/secretmanager/v1",
615615
},
616616
want: "cloud.google.com/go/secretmanager/apiv1;secretmanager",
617617
},
@@ -621,10 +621,9 @@ func TestBuildGAPICImportPath(t *testing.T) {
621621
Name: "storage",
622622
},
623623
goAPI: &config.GoAPI{
624-
ClientDirectory: "internal",
625-
ClientPackageOverride: "storage",
626-
ImportPath: "storage/internal/apiv2",
627-
Path: "google/storage/v2",
624+
ClientPackage: "storage",
625+
ImportPath: "storage/internal/apiv2",
626+
Path: "google/storage/v2",
628627
},
629628
want: "cloud.google.com/go/storage/internal/apiv2;storage",
630629
},
@@ -760,9 +759,9 @@ func TestBuildGAPICOpts(t *testing.T) {
760759
Version: "1.2.3",
761760
},
762761
goAPI: &config.GoAPI{
763-
ClientDirectory: "secretmanager",
764-
ImportPath: "secretmanager/apiv1",
765-
Path: "google/cloud/secretmanager/v1",
762+
ClientPackage: "secretmanager",
763+
ImportPath: "secretmanager/apiv1",
764+
Path: "google/cloud/secretmanager/v1",
766765
},
767766
googleapisDir: googleapisDir,
768767
want: []string{
@@ -783,7 +782,7 @@ func TestBuildGAPICOpts(t *testing.T) {
783782
Version: "1.2.3",
784783
},
785784
goAPI: &config.GoAPI{
786-
ClientDirectory: "secretmanager",
785+
ClientPackage: "secretmanager",
787786
ImportPath: "secretmanager/apiv1",
788787
NoRESTNumericEnums: true,
789788
Path: "google/cloud/secretmanager/v1",
@@ -806,9 +805,9 @@ func TestBuildGAPICOpts(t *testing.T) {
806805
Version: "0.2.3",
807806
},
808807
goAPI: &config.GoAPI{
809-
ClientDirectory: "secretmanager",
810-
ImportPath: "secretmanager/apiv1",
811-
Path: "google/cloud/secretmanager/v1",
808+
ClientPackage: "secretmanager",
809+
ImportPath: "secretmanager/apiv1",
810+
Path: "google/cloud/secretmanager/v1",
812811
},
813812
googleapisDir: googleapisDir,
814813
want: []string{
@@ -829,9 +828,9 @@ func TestBuildGAPICOpts(t *testing.T) {
829828
Version: "1.2.3",
830829
},
831830
goAPI: &config.GoAPI{
832-
ClientDirectory: "gkehub",
833-
ImportPath: "gkehub/apiv1",
834-
Path: "google/cloud/gkehub/v1",
831+
ClientPackage: "gkehub",
832+
ImportPath: "gkehub/apiv1",
833+
Path: "google/cloud/gkehub/v1",
835834
},
836835
googleapisDir: googleapisDir,
837836
want: []string{
@@ -851,10 +850,10 @@ func TestBuildGAPICOpts(t *testing.T) {
851850
Version: "1.2.3",
852851
},
853852
goAPI: &config.GoAPI{
854-
ClientDirectory: "gkehub",
855-
ImportPath: "gkehub/apiv1",
856-
NoMetadata: true,
857-
Path: "google/cloud/gkehub/v1",
853+
ClientPackage: "gkehub",
854+
ImportPath: "gkehub/apiv1",
855+
NoMetadata: true,
856+
Path: "google/cloud/gkehub/v1",
858857
},
859858
googleapisDir: googleapisDir,
860859
want: []string{
@@ -874,7 +873,7 @@ func TestBuildGAPICOpts(t *testing.T) {
874873
APIs: []*config.API{{Path: "google/cloud/bigquery/v2"}},
875874
},
876875
goAPI: &config.GoAPI{
877-
ClientDirectory: "bigquery",
876+
ClientPackage: "bigquery",
878877
EnabledGeneratorFeatures: []string{"F_wrapper_types_for_page_size"},
879878
ImportPath: "bigquery/v2/apiv2",
880879
Path: "google/cloud/bigquery/v2",
@@ -899,9 +898,9 @@ func TestBuildGAPICOpts(t *testing.T) {
899898
APIs: []*config.API{{Path: "google/cloud/apigeeconnect/v1"}},
900899
},
901900
goAPI: &config.GoAPI{
902-
ClientDirectory: "apigeeconnect",
903-
ImportPath: "apigeeconnect/apiv1",
904-
Path: "google/cloud/apigeeconnect/v1",
901+
ClientPackage: "apigeeconnect",
902+
ImportPath: "apigeeconnect/apiv1",
903+
Path: "google/cloud/apigeeconnect/v1",
905904
},
906905
googleapisDir: googleapisDir,
907906
want: []string{
@@ -921,7 +920,7 @@ func TestBuildGAPICOpts(t *testing.T) {
921920
APIs: []*config.API{{Path: "google/cloud/compute/v1"}},
922921
},
923922
goAPI: &config.GoAPI{
924-
ClientDirectory: "compute",
923+
ClientPackage: "compute",
925924
ImportPath: "compute/apiv1",
926925
HasDiregapic: true,
927926
NoRESTNumericEnums: true,

internal/librarian/golang/module.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ func Fill(library *config.Library) *config.Library {
3636
Path: api.Path,
3737
}
3838
}
39-
importPath, clientDir := defaultImportPathAndClientPkg(api.Path)
39+
importPath, clientPkg := defaultImportPathAndClientPkg(api.Path)
4040
if goAPI.ImportPath == "" {
4141
goAPI.ImportPath = importPath
4242
}
43-
if goAPI.ClientDirectory == "" {
44-
goAPI.ClientDirectory = clientDir
43+
if goAPI.ClientPackage == "" {
44+
goAPI.ClientPackage = clientPkg
4545
}
4646
goAPIs = append(goAPIs, goAPI)
4747
}

0 commit comments

Comments
 (0)