Skip to content

Commit 0a8aacb

Browse files
authored
feat(internal/librarian/java): adds TransportOverride for .repo-metadata and update migrate tool (#5483)
Adds TransportOverride for .repo-metadata only, and update migrate tool to migrate from generation_config.yaml field. Fix #5480
1 parent defec8e commit 0a8aacb

6 files changed

Lines changed: 53 additions & 13 deletions

File tree

doc/config-schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ This document describes the schema for the librarian.yaml.
286286
| `billing_not_required` | bool | Indicates whether the API does NOT require billing. This is typically false. |
287287
| `rest_documentation` | string | Is the URL for the REST documentation. |
288288
| `rpc_documentation` | string | Is the URL for the RPC documentation. |
289+
| `transport_override` | string | Allows the "transport" field in .repo-metadata.json to be overridden. |
289290

290291
## NodejsAPI Configuration
291292

internal/config/language.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ type JavaModule struct {
566566

567567
// RpcDocumentation is the URL for the RPC documentation.
568568
RpcDocumentation string `yaml:"rpc_documentation,omitempty"`
569+
570+
// TransportOverride allows the "transport" field in .repo-metadata.json
571+
// to be overridden.
572+
TransportOverride string `yaml:"transport_override,omitempty"`
569573
}
570574

571575
// JavaAPI represents configuration for a single API within a Java module.

internal/librarian/java/repometadata.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ func deriveRepoMetadata(cfg *config.Config, library *config.Library, googleapisD
148148
metadata.RecommendedPackage = library.Java.RecommendedPackage
149149
metadata.RestDocumentation = library.Java.RestDocumentation
150150
metadata.RpcDocumentation = library.Java.RpcDocumentation
151+
if library.Java.TransportOverride != "" {
152+
metadata.Transport = library.Java.TransportOverride
153+
}
151154
}
152155

153156
// distribution_name default for Java is groupId:artifactId
@@ -161,10 +164,12 @@ func deriveRepoMetadata(cfg *config.Config, library *config.Library, googleapisD
161164
metadata.ClientDocumentation = fmt.Sprintf("https://cloud.google.com/java/docs/reference/%s/latest/overview", artifactID)
162165
}
163166
// transport
164-
apiCfg, err := serviceconfig.Find(googleapisDir, library.APIs[0].Path, config.LanguageJava)
165-
if err != nil {
166-
return nil, fmt.Errorf("failed to find api config: %w", err)
167+
if metadata.Transport == "" {
168+
apiCfg, err := serviceconfig.Find(googleapisDir, library.APIs[0].Path, config.LanguageJava)
169+
if err != nil {
170+
return nil, fmt.Errorf("failed to find api config: %w", err)
171+
}
172+
metadata.Transport = apiCfg.RepoMetadataTransport(config.LanguageJava)
167173
}
168-
metadata.Transport = apiCfg.RepoMetadataTransport(config.LanguageJava)
169174
return metadata, nil
170175
}

internal/librarian/java/repometadata_test.go

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ func TestRepoMetadata_write(t *testing.T) {
7373
func TestDeriveRepoMetadata_Overrides(t *testing.T) {
7474
t.Parallel()
7575
apiPath := "google/cloud/secretmanager/v1"
76-
googleapis := "internal/testdata/googleapis"
76+
googleapis := "../../testdata/googleapis"
7777

7878
cfg := sample.Config()
7979
cfg.Language = config.LanguageJava
8080
cfg.Repo = "googleapis/google-cloud-java"
8181
s := sample.RepoMetadata()
82+
wantNamePretty := "Secret Manager"
83+
wantProductDoc := "https://cloud.google.com/secret-manager/"
84+
wantAPIDescription := "Stores sensitive data such as API keys, passwords, and certificates.\nProvides convenience while improving security."
8285
for _, test := range []struct {
8386
name string
8487
java *config.JavaModule
@@ -121,20 +124,45 @@ func TestDeriveRepoMetadata_Overrides(t *testing.T) {
121124
APIShortnameOverride: "custom-shortname",
122125
},
123126
want: &repoMetadata{
124-
APIShortname: "custom-shortname",
125-
ClientDocumentation: "https://cloud.google.com/java/docs/reference/google-cloud-secretmanager/latest/overview",
126-
ReleaseLevel: "stable",
127-
Transport: "both",
128-
Language: "java",
129-
Repo: "googleapis/google-cloud-java",
130-
RepoShort: "java-secretmanager",
131-
DistributionName: "com.google.cloud:google-cloud-secretmanager",
127+
APIShortname: "custom-shortname",
128+
NamePretty: wantNamePretty,
129+
ProductDocumentation: wantProductDoc,
130+
APIDescription: wantAPIDescription,
131+
ClientDocumentation: "https://cloud.google.com/java/docs/reference/google-cloud-secretmanager/latest/overview",
132+
ReleaseLevel: "stable",
133+
Transport: "both",
134+
Language: "java",
135+
Repo: "googleapis/google-cloud-java",
136+
RepoShort: "java-secretmanager",
137+
DistributionName: "com.google.cloud:google-cloud-secretmanager",
132138
// API ID is also override.
133139
APIID: "custom-shortname.googleapis.com",
134140
LibraryType: "GAPIC_AUTO",
135141
RequiresBilling: true,
136142
},
137143
},
144+
{
145+
name: "transport override",
146+
java: &config.JavaModule{
147+
TransportOverride: "rest",
148+
},
149+
want: &repoMetadata{
150+
APIShortname: "secretmanager",
151+
NamePretty: wantNamePretty,
152+
ProductDocumentation: wantProductDoc,
153+
APIDescription: wantAPIDescription,
154+
ClientDocumentation: "https://cloud.google.com/java/docs/reference/google-cloud-secretmanager/latest/overview",
155+
ReleaseLevel: "stable",
156+
Transport: "rest",
157+
Language: "java",
158+
Repo: "googleapis/google-cloud-java",
159+
RepoShort: "java-secretmanager",
160+
DistributionName: "com.google.cloud:google-cloud-secretmanager",
161+
APIID: "secretmanager.googleapis.com",
162+
LibraryType: "GAPIC_AUTO",
163+
RequiresBilling: true,
164+
},
165+
},
138166
} {
139167
t.Run(test.name, func(t *testing.T) {
140168
library := &config.Library{

tool/cmd/migrate/java.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ func buildConfig(gen *GenerationConfig, repoPath string, src *config.Source, ver
291291
BillingNotRequired: invertBoolPtr(l.RequiresBilling),
292292
RestDocumentation: l.RestDocumentation,
293293
RpcDocumentation: l.RpcDocumentation,
294+
TransportOverride: l.Transport,
294295
},
295296
}
296297
if override, ok := keepOverride[lib.Name]; ok {

tool/cmd/migrate/java_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ func TestBuildConfig(t *testing.T) {
373373
BillingNotRequired: true,
374374
RestDocumentation: "https://rest-doc.com",
375375
RpcDocumentation: "https://rpc-doc.com",
376+
TransportOverride: "grpc",
376377
},
377378
},
378379
},

0 commit comments

Comments
 (0)