diff --git a/internal/librarian/generate.go b/internal/librarian/generate.go index a58280b9ca..c27a2b5cc5 100644 --- a/internal/librarian/generate.go +++ b/internal/librarian/generate.go @@ -269,6 +269,8 @@ func defaultOutput(language string, name, api, defaultOut string) string { return python.DefaultOutput(name, defaultOut) case config.LanguageRust: return rust.DefaultOutput(api, defaultOut) + case config.LanguageSwift: + return swift.DefaultOutput(api, defaultOut) default: return defaultOut } diff --git a/internal/librarian/swift/default_output.go b/internal/librarian/swift/default_output.go new file mode 100644 index 0000000000..4b5de9d746 --- /dev/null +++ b/internal/librarian/swift/default_output.go @@ -0,0 +1,23 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package swift + +import "path/filepath" + +// DefaultOutput derives an output path from an API path and a default +// output directory. +func DefaultOutput(api, defaultOutput string) string { + return filepath.Join(defaultOutput, api) +} diff --git a/internal/librarian/swift/default_output_test.go b/internal/librarian/swift/default_output_test.go new file mode 100644 index 0000000000..7df40ed163 --- /dev/null +++ b/internal/librarian/swift/default_output_test.go @@ -0,0 +1,62 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package swift + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestDefaultOutput(t *testing.T) { + for _, tt := range []struct { + name string + api string + defOut string + want string + }{ + { + name: "simple", + api: "secretmanager", + defOut: "packages", + want: "packages/secretmanager", + }, + { + name: "empty default", + api: "secretmanager", + defOut: "", + want: "secretmanager", + }, + { + name: "nested default", + api: "secretmanager", + defOut: "a/b/c", + want: "a/b/c/secretmanager", + }, + { + name: "api path", + api: "google/cloud/secretmanager/v1", + defOut: "generated", + want: "generated/google/cloud/secretmanager/v1", + }, + } { + t.Run(tt.name, func(t *testing.T) { + got := DefaultOutput(tt.api, tt.defOut) + if diff := cmp.Diff(tt.want, got); diff != "" { + t.Errorf("mismatch (-want +got):\n%s", diff) + } + }) + } +}