Skip to content

Commit cf82aaf

Browse files
authored
refactor(internal/librarian): do not derive API path for Go (#4406)
This change modifies Librarian to skip deriving the API path for Go libraries when one is not explicitly provided. Previously, if a library was not a veneer and had no APIs defined, Librarian would append an empty API entry and attempt to derive its path. However, for Go, the library name does not contain the relevant information needed to accurately derive the API path. As a result, Go library with no API does not need `veneer: true`. For #4276 Fixes #4279
1 parent 7806abd commit cf82aaf

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

internal/librarian/golang/module_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ func TestFill(t *testing.T) {
178178
},
179179
},
180180
},
181+
{
182+
name: "no API",
183+
library: &config.Library{
184+
Name: "auth",
185+
},
186+
want: &config.Library{
187+
Name: "auth",
188+
Go: &config.GoModule{},
189+
},
190+
},
181191
} {
182192
t.Run(test.name, func(t *testing.T) {
183193
got, err := Fill(test.library)

internal/librarian/library.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ func libraryOutput(language string, lib *config.Library, defaults *config.Defaul
191191
// applyDefaults applies language-specific derivations and fills defaults.
192192
func applyDefaults(language string, lib *config.Library, defaults *config.Default) (*config.Library, error) {
193193
if !isVeneer(language, lib) {
194-
if len(lib.APIs) == 0 {
194+
if len(lib.APIs) == 0 && language != config.LanguageGo {
195+
// Do not derive API path for Go because the library name
196+
// doesn't contain relevant info.
195197
lib.APIs = append(lib.APIs, &config.API{})
196198
}
197199
for _, api := range lib.APIs {
@@ -204,7 +206,11 @@ func applyDefaults(language string, lib *config.Library, defaults *config.Defaul
204206
if isVeneer(language, lib) {
205207
return nil, fmt.Errorf("veneer %q requires an explicit output path", lib.Name)
206208
}
207-
lib.Output = defaultOutput(language, lib.Name, lib.APIs[0].Path, defaults.Output)
209+
var apiPath string
210+
if len(lib.APIs) > 0 {
211+
apiPath = lib.APIs[0].Path
212+
}
213+
lib.Output = defaultOutput(language, lib.Name, apiPath, defaults.Output)
208214
}
209215
return fillLibraryDefaults(language, fillDefaults(lib, defaults))
210216
}

internal/librarian/library_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ func TestPrepareLibrary(t *testing.T) {
523523
wantOutput: "src/generated/cloud/orgpolicy/v1",
524524
wantAPIPath: "google/cloud/orgpolicy/v1",
525525
},
526+
{
527+
name: "Go lib without api path",
528+
language: config.LanguageGo,
529+
wantOutput: "src/generated",
530+
},
526531
} {
527532
t.Run(test.name, func(t *testing.T) {
528533
lib := &config.Library{

0 commit comments

Comments
 (0)