Skip to content

Commit 3f6cfed

Browse files
authored
feat(internal/librarian/nodejs): add metadata_name_override and name_pretty_override support (#6603)
This pull request adds metadata_name_override and name_pretty_override configuration fields to NodejsPackage in librarian.yaml . Currently, Librarian infers name and name_pretty in `.repo-metadata.json` directly from the backend service config ( api.ShortName and api.Title ). When multiple packages share a single service authority (e.g., @google-cloud/dialogflow and @google-cloud/dialogflow-cx both generating from dialogflow.googleapis.com ), Librarian overwrites both `.repo-metadata.json` files with identical values ( "dialogflow" / "Dialogflow" ), causing config collisions. Adding these override fields aligns Node.js with Java ( name_pretty_override ) and Python ( metadata_name_override ), allowing packages with shared service authorities to explicitly preserve their unique metadata names. For #6453
1 parent b8e50a5 commit 3f6cfed

5 files changed

Lines changed: 46 additions & 2 deletions

File tree

doc/config-schema.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ This document describes the schema for the librarian.yaml.
364364
| `nodejs_apis` | list of [NodejsAPI](#nodejsapi-configuration) (optional) | Is a list of Node.js-specific API configurations. |
365365
| `package_name` | string | Is the npm package name (e.g., "@google-cloud/access-approval"). |
366366
| `client_documentation_override` | string | Allows the client_documentation field in .repo-metadata.json to be overridden from the default that's inferred. |
367+
| `metadata_name_override` | string | Allows the name field in .repo-metadata.json to be overridden. |
368+
| `name_pretty_override` | string | Allows the name_pretty field in .repo-metadata.json to be overridden. |
367369

368370
## PythonDefault Configuration
369371

internal/config/language.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,12 @@ type NodejsPackage struct {
777777
// ClientDocumentationOverride allows the client_documentation field in
778778
// .repo-metadata.json to be overridden from the default that's inferred.
779779
ClientDocumentationOverride string `yaml:"client_documentation_override,omitempty"`
780+
781+
// MetadataNameOverride allows the name field in .repo-metadata.json to be overridden.
782+
MetadataNameOverride string `yaml:"metadata_name_override,omitempty"`
783+
784+
// NamePrettyOverride allows the name_pretty field in .repo-metadata.json to be overridden.
785+
NamePrettyOverride string `yaml:"name_pretty_override,omitempty"`
780786
}
781787

782788
// NodejsAPI represents configuration for a single API within a Node.js package.

internal/librarian/library.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,12 @@ func mergeNodejs(dst, src *config.NodejsPackage) *config.NodejsPackage {
674674
if src.ClientDocumentationOverride != "" {
675675
res.ClientDocumentationOverride = src.ClientDocumentationOverride
676676
}
677+
if src.MetadataNameOverride != "" {
678+
res.MetadataNameOverride = src.MetadataNameOverride
679+
}
680+
if src.NamePrettyOverride != "" {
681+
res.NamePrettyOverride = src.NamePrettyOverride
682+
}
677683
return &res
678684
}
679685

internal/librarian/nodejs/generate_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,28 @@ func TestWriteRepoMetadata(t *testing.T) {
11251125
return w
11261126
},
11271127
},
1128+
{
1129+
name: "metadata name and name pretty overrides",
1130+
library: &config.Library{
1131+
Name: "google-cloud-dialogflow-cx",
1132+
APIs: []*config.API{{Path: "google/cloud/secretmanager/v1"}},
1133+
Nodejs: &config.NodejsPackage{
1134+
MetadataNameOverride: "dialogflow-cx",
1135+
NamePrettyOverride: "Dialogflow CX API",
1136+
},
1137+
},
1138+
want: func() *repometadata.RepoMetadata {
1139+
w := sample.RepoMetadata()
1140+
w.DistributionName = "@google-cloud/dialogflow-cx"
1141+
w.Language = cfg.Language
1142+
w.Repo = cfg.Repo
1143+
w.ClientDocumentation = "https://cloud.google.com/nodejs/docs/reference/dialogflow-cx/latest"
1144+
w.ProductDocumentation = "https://cloud.google.com/secret-manager/docs"
1145+
w.Name = "dialogflow-cx"
1146+
w.NamePretty = "Dialogflow CX API"
1147+
return w
1148+
},
1149+
},
11281150
} {
11291151
t.Run(test.name, func(t *testing.T) {
11301152
outDir := t.TempDir()

internal/librarian/nodejs/repometadata.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ func generateRepoMetadata(cfg *config.Config, library *config.Library, googleapi
3535
metadata.ClientDocumentation = fmt.Sprintf("https://cloud.google.com/nodejs/docs/reference/%s/latest", pkgSuffix)
3636
}
3737

38-
if library.Nodejs != nil && library.Nodejs.ClientDocumentationOverride != "" {
39-
metadata.ClientDocumentation = library.Nodejs.ClientDocumentationOverride
38+
if library.Nodejs != nil {
39+
if library.Nodejs.ClientDocumentationOverride != "" {
40+
metadata.ClientDocumentation = library.Nodejs.ClientDocumentationOverride
41+
}
42+
if library.Nodejs.MetadataNameOverride != "" {
43+
metadata.Name = library.Nodejs.MetadataNameOverride
44+
}
45+
if library.Nodejs.NamePrettyOverride != "" {
46+
metadata.NamePretty = library.Nodejs.NamePrettyOverride
47+
}
4048
}
4149

4250
if strings.HasPrefix(metadata.ProductDocumentation, "https://cloud.google.com/") {

0 commit comments

Comments
 (0)