Skip to content

Commit 9515ed4

Browse files
authored
fix(internal/librarian): tidy to skip duplicate API path check for hardcoded list in java (#5707)
Add logic in tidy to skip duplicate API path checks for this hardcoded list when language is Java. These API paths are duplicated in java's librarian.yaml config because java geneates proto and grpc modules from these into [java-iam](https://github.com/googleapis/google-cloud-java/tree/main/java-iam) and gapic modules separately into [java-iam-policy](https://github.com/googleapis/google-cloud-java/tree/main/java-iam-policy). Fix #5706
1 parent c4bd40f commit 9515ed4

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

internal/librarian/tidy.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ var (
3636
errDuplicateLibraryName = errors.New("duplicate library name")
3737
errDuplicateAPIPath = errors.New("duplicate api path")
3838
errNoGoogleapiSourceInfo = errors.New("googleapis source not configured in librarian.yaml")
39+
40+
// javaSkipDuplicatePaths lists special API paths that are allowed to appear in multiple
41+
// libraries in Java without triggering the duplicate API path error.
42+
// These are paths are duplicated in java because their generated code splits
43+
// between java-iam and java-iam-policy.
44+
javaSkipDuplicatePaths = map[string]bool{
45+
"google/iam/v1": true,
46+
"google/iam/v2": true,
47+
"google/iam/v2beta": true,
48+
"google/iam/v3": true,
49+
"google/iam/v3beta": true,
50+
}
3951
)
4052

4153
func tidyCommand() *cli.Command {
@@ -139,6 +151,9 @@ func validateLibraries(cfg *config.Config) error {
139151
}
140152
for _, ch := range lib.APIs {
141153
if ch.Path != "" {
154+
if cfg.Language == config.LanguageJava && javaSkipDuplicatePaths[ch.Path] {
155+
continue
156+
}
142157
pathCount[ch.Path]++
143158
}
144159
}

internal/librarian/tidy_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ func TestValidateLibraries(t *testing.T) {
6464
language: config.LanguageJava,
6565
wantErr: java.ErrInvalidDistributionName,
6666
},
67+
{
68+
name: "skipped duplicate api paths",
69+
libraries: []*config.Library{
70+
{
71+
Name: "lib1",
72+
APIs: []*config.API{{Path: "google/iam/v1"}},
73+
},
74+
{
75+
Name: "lib2",
76+
APIs: []*config.API{{Path: "google/iam/v1"}},
77+
},
78+
},
79+
language: config.LanguageJava,
80+
},
81+
{
82+
name: "duplicate api paths not skipped for non-java",
83+
libraries: []*config.Library{
84+
{
85+
Name: "lib1",
86+
APIs: []*config.API{{Path: "google/iam/v1"}},
87+
},
88+
{
89+
Name: "lib2",
90+
APIs: []*config.API{{Path: "google/iam/v1"}},
91+
},
92+
},
93+
language: config.LanguagePython,
94+
wantErr: errDuplicateAPIPath,
95+
},
6796
} {
6897
t.Run(test.name, func(t *testing.T) {
6998
cfg := &config.Config{

0 commit comments

Comments
 (0)