Skip to content

Commit bce1fd3

Browse files
authored
feat(internal/rust): add missing codec options (#3101)
The toSidekickConfig function now supports conversions to sidekick codec options for title-override, description-override, skipped-ids, and name-overrides. For #2966
1 parent ce8aceb commit bce1fd3

File tree

2 files changed

+132
-2
lines changed

2 files changed

+132
-2
lines changed

internal/librarian/internal/rust/codec.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ func toSidekickConfig(library *config.Library, channel *config.Channel, googleap
3131
source["discovery-root"] = discoveryDir
3232
source["roots"] = "discovery,googleapis"
3333
}
34+
if library.Rust != nil {
35+
if library.Rust.TitleOverride != "" {
36+
source["title-override"] = library.Rust.TitleOverride
37+
}
38+
if library.Rust.DescriptionOverride != "" {
39+
source["description-override"] = library.Rust.DescriptionOverride
40+
}
41+
if len(library.Rust.SkippedIds) > 0 {
42+
source["skipped-ids"] = strings.Join(library.Rust.SkippedIds, ",")
43+
}
44+
}
3445
sidekickCfg := &sidekickconfig.Config{
3546
General: sidekickconfig.GeneralConfig{
3647
Language: "rust",
@@ -41,7 +52,6 @@ func toSidekickConfig(library *config.Library, channel *config.Channel, googleap
4152
Source: source,
4253
Codec: buildCodec(library),
4354
}
44-
4555
if library.Rust != nil {
4656
if len(library.Rust.DocumentationOverrides) > 0 {
4757
sidekickCfg.CommentOverrides = make([]sidekickconfig.DocumentationOverride, len(library.Rust.DocumentationOverrides))
@@ -124,7 +134,9 @@ func buildCodec(library *config.Library) map[string]string {
124134
if rust.GenerateSetterSamples {
125135
codec["generate-setter-samples"] = "true"
126136
}
127-
137+
if rust.NameOverrides != "" {
138+
codec["name-overrides"] = rust.NameOverrides
139+
}
128140
for _, dep := range rust.PackageDependencies {
129141
codec["package:"+dep.Name] = formatPackageDependency(dep)
130142
}

internal/librarian/internal/rust/codec_test.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,124 @@ func TestToSidekickConfig(t *testing.T) {
342342
},
343343
},
344344
},
345+
{
346+
name: "with title override",
347+
library: &config.Library{
348+
Name: "google-cloud-apps-script-type-gmail",
349+
Rust: &config.RustCrate{
350+
TitleOverride: "Google Apps Script Types",
351+
},
352+
},
353+
channel: &config.Channel{
354+
Path: "google/apps/script/type/gmail",
355+
},
356+
googleapisDir: "/tmp/googleapis",
357+
want: &sidekickconfig.Config{
358+
General: sidekickconfig.GeneralConfig{
359+
Language: "rust",
360+
SpecificationFormat: "protobuf",
361+
SpecificationSource: "google/apps/script/type/gmail",
362+
},
363+
Source: map[string]string{
364+
"googleapis-root": "/tmp/googleapis",
365+
"title-override": "Google Apps Script Types",
366+
},
367+
Codec: map[string]string{
368+
"package-name-override": "google-cloud-apps-script-type-gmail",
369+
},
370+
},
371+
},
372+
{
373+
name: "with description override",
374+
library: &config.Library{
375+
Name: "google-cloud-longrunning",
376+
Rust: &config.RustCrate{
377+
DescriptionOverride: "Defines types and an abstract service to handle long-running operations.",
378+
},
379+
},
380+
channel: &config.Channel{
381+
Path: "google/longrunning",
382+
ServiceConfig: "google/longrunning/longrunning.yaml",
383+
},
384+
googleapisDir: "/tmp/googleapis",
385+
want: &sidekickconfig.Config{
386+
General: sidekickconfig.GeneralConfig{
387+
Language: "rust",
388+
SpecificationFormat: "protobuf",
389+
ServiceConfig: "google/longrunning/longrunning.yaml",
390+
SpecificationSource: "google/longrunning",
391+
},
392+
Source: map[string]string{
393+
"googleapis-root": "/tmp/googleapis",
394+
"description-override": "Defines types and an abstract service to handle long-running operations.",
395+
},
396+
Codec: map[string]string{
397+
"package-name-override": "google-cloud-longrunning",
398+
},
399+
},
400+
},
401+
{
402+
name: "with skipped ids",
403+
library: &config.Library{
404+
Name: "google-cloud-spanner-admin-database-v1",
405+
Rust: &config.RustCrate{
406+
SkippedIds: []string{
407+
".google.spanner.admin.database.v1.DatabaseAdmin.InternalUpdateGraphOperation",
408+
".google.spanner.admin.database.v1.InternalUpdateGraphOperationRequest",
409+
".google.spanner.admin.database.v1.InternalUpdateGraphOperationResponse",
410+
},
411+
},
412+
},
413+
channel: &config.Channel{
414+
Path: "google/spanner/admin/database/v1",
415+
ServiceConfig: "google/spanner/admin/database/v1/spanner.yaml",
416+
},
417+
googleapisDir: "/tmp/googleapis",
418+
want: &sidekickconfig.Config{
419+
General: sidekickconfig.GeneralConfig{
420+
Language: "rust",
421+
SpecificationFormat: "protobuf",
422+
ServiceConfig: "google/spanner/admin/database/v1/spanner.yaml",
423+
SpecificationSource: "google/spanner/admin/database/v1",
424+
},
425+
Source: map[string]string{
426+
"googleapis-root": "/tmp/googleapis",
427+
"skipped-ids": ".google.spanner.admin.database.v1.DatabaseAdmin.InternalUpdateGraphOperation,.google.spanner.admin.database.v1.InternalUpdateGraphOperationRequest,.google.spanner.admin.database.v1.InternalUpdateGraphOperationResponse",
428+
},
429+
Codec: map[string]string{
430+
"package-name-override": "google-cloud-spanner-admin-database-v1",
431+
},
432+
},
433+
},
434+
{
435+
name: "with name overrides",
436+
library: &config.Library{
437+
Name: "google-cloud-storageinsights-v1",
438+
Rust: &config.RustCrate{
439+
NameOverrides: ".google.cloud.storageinsights.v1.DatasetConfig.cloud_storage_buckets=CloudStorageBucketsOneOf,.google.cloud.storageinsights.v1.DatasetConfig.cloud_storage_locations=CloudStorageLocationsOneOf",
440+
},
441+
},
442+
channel: &config.Channel{
443+
Path: "google/cloud/storageinsights/v1",
444+
ServiceConfig: "google/cloud/storageinsights/v1/storageinsights_v1.yaml",
445+
},
446+
googleapisDir: "/tmp/googleapis",
447+
want: &sidekickconfig.Config{
448+
General: sidekickconfig.GeneralConfig{
449+
Language: "rust",
450+
SpecificationFormat: "protobuf",
451+
ServiceConfig: "google/cloud/storageinsights/v1/storageinsights_v1.yaml",
452+
SpecificationSource: "google/cloud/storageinsights/v1",
453+
},
454+
Source: map[string]string{
455+
"googleapis-root": "/tmp/googleapis",
456+
},
457+
Codec: map[string]string{
458+
"package-name-override": "google-cloud-storageinsights-v1",
459+
"name-overrides": ".google.cloud.storageinsights.v1.DatasetConfig.cloud_storage_buckets=CloudStorageBucketsOneOf,.google.cloud.storageinsights.v1.DatasetConfig.cloud_storage_locations=CloudStorageLocationsOneOf",
460+
},
461+
},
462+
},
345463
} {
346464
t.Run(test.name, func(t *testing.T) {
347465
got := toSidekickConfig(test.library, test.channel, test.googleapisDir, test.discoveryDir)

0 commit comments

Comments
 (0)