Skip to content

Commit 64cf522

Browse files
authored
feat(librarian/swift): default output directory (#5024)
Librarian needs to compute the default output directory for an API. For Swift, I am selecting the full path of the API, as we do in most languages. The `librarian.yaml` file will include a prefix, such as `generated/`.
1 parent 9d47a48 commit 64cf522

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

internal/librarian/generate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ func defaultOutput(language string, name, api, defaultOut string) string {
269269
return python.DefaultOutput(name, defaultOut)
270270
case config.LanguageRust:
271271
return rust.DefaultOutput(api, defaultOut)
272+
case config.LanguageSwift:
273+
return swift.DefaultOutput(api, defaultOut)
272274
default:
273275
return defaultOut
274276
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package swift
16+
17+
import "path/filepath"
18+
19+
// DefaultOutput derives an output path from an API path and a default
20+
// output directory.
21+
func DefaultOutput(api, defaultOutput string) string {
22+
return filepath.Join(defaultOutput, api)
23+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package swift
16+
17+
import (
18+
"testing"
19+
20+
"github.com/google/go-cmp/cmp"
21+
)
22+
23+
func TestDefaultOutput(t *testing.T) {
24+
for _, tt := range []struct {
25+
name string
26+
api string
27+
defOut string
28+
want string
29+
}{
30+
{
31+
name: "simple",
32+
api: "secretmanager",
33+
defOut: "packages",
34+
want: "packages/secretmanager",
35+
},
36+
{
37+
name: "empty default",
38+
api: "secretmanager",
39+
defOut: "",
40+
want: "secretmanager",
41+
},
42+
{
43+
name: "nested default",
44+
api: "secretmanager",
45+
defOut: "a/b/c",
46+
want: "a/b/c/secretmanager",
47+
},
48+
{
49+
name: "api path",
50+
api: "google/cloud/secretmanager/v1",
51+
defOut: "generated",
52+
want: "generated/google/cloud/secretmanager/v1",
53+
},
54+
} {
55+
t.Run(tt.name, func(t *testing.T) {
56+
got := DefaultOutput(tt.api, tt.defOut)
57+
if diff := cmp.Diff(tt.want, got); diff != "" {
58+
t.Errorf("mismatch (-want +got):\n%s", diff)
59+
}
60+
})
61+
}
62+
}

0 commit comments

Comments
 (0)