Skip to content

Commit 8d2dd85

Browse files
authored
refactor(internal/repometadata): use library to generate metadata (#4068)
Refactor library struct as one of the inputs to generate metadata from API. In Go clients, some metadata, e.g., documentation url and distribution name, requires Go specific configuration from the library. This is a preparation step for Go metadata generation. For #3617
1 parent 9a3cef9 commit 8d2dd85

1 file changed

Lines changed: 21 additions & 36 deletions

File tree

internal/repometadata/repometadata.go

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ var (
3333
errNoServiceConfig = errors.New("library has no service config from which to get metadata")
3434
)
3535

36-
// LibraryInfo contains information about a library that is not available in the service config.
37-
type LibraryInfo struct {
38-
// DescriptionOverride overrides the library description from the service config.
39-
DescriptionOverride string
40-
// Name is the name of the library distribution package.
41-
Name string
42-
// ReleaseLevel is the release level (e.g., "stable", "preview").
43-
ReleaseLevel string
44-
}
45-
4636
// RepoMetadata represents the .repo-metadata.json file structure.
4737
type RepoMetadata struct {
4838
// APIDescription is the description of the API.
@@ -105,36 +95,31 @@ func FromLibrary(library *config.Library, language, repo, googleapisDir, default
10595
if api.ServiceConfig == "" {
10696
return fmt.Errorf("failed to generate metadata for %s: %w", library.Name, errNoServiceConfig)
10797
}
108-
info := &LibraryInfo{
109-
DescriptionOverride: library.DescriptionOverride,
110-
Name: library.Name,
111-
ReleaseLevel: library.ReleaseLevel,
112-
}
113-
return FromAPI(api, info, language, repo, defaultVersion, outdir)
98+
return FromAPI(api, library, language, repo, defaultVersion, outdir)
11499
}
115100

116-
// FromAPI generates the .repo-metadata.json file from a serviceconfig.API and additional library information.
117-
func FromAPI(api *serviceconfig.API, info *LibraryInfo, language, repo, defaultVersion, outputDir string) error {
101+
// FromAPI generates the .repo-metadata.json file from a serviceconfig.API and library information.
102+
func FromAPI(api *serviceconfig.API, library *config.Library, language, repo, defaultVersion, outputDir string) error {
118103
clientDocURL := buildClientDocURL(language, extractNameFromAPIID(api.ServiceName))
119-
metadata := &RepoMetadata{
120-
APIID: api.ServiceName,
121-
NamePretty: cleanTitle(api.Title),
122-
DefaultVersion: defaultVersion,
123-
ClientDocumentation: clientDocURL,
124-
ReleaseLevel: info.ReleaseLevel,
125-
Language: language,
126-
LibraryType: "GAPIC_AUTO",
127-
Repo: repo,
128-
DistributionName: info.Name,
104+
apiDescription := api.Description
105+
if library.DescriptionOverride != "" {
106+
apiDescription = library.DescriptionOverride
129107
}
130-
131-
metadata.ProductDocumentation = extractBaseProductURL(api.DocumentationURI)
132-
metadata.IssueTracker = api.NewIssueURI
133-
metadata.APIShortname = api.ShortName
134-
metadata.Name = api.ShortName
135-
metadata.APIDescription = api.Description
136-
if info.DescriptionOverride != "" {
137-
metadata.APIDescription = info.DescriptionOverride
108+
metadata := &RepoMetadata{
109+
APIDescription: apiDescription,
110+
APIID: api.ServiceName,
111+
APIShortname: api.ShortName,
112+
ClientDocumentation: clientDocURL,
113+
DefaultVersion: defaultVersion,
114+
DistributionName: library.Name,
115+
IssueTracker: api.NewIssueURI,
116+
Language: language,
117+
LibraryType: "GAPIC_AUTO",
118+
Name: api.ShortName,
119+
NamePretty: cleanTitle(api.Title),
120+
ProductDocumentation: extractBaseProductURL(api.DocumentationURI),
121+
ReleaseLevel: library.ReleaseLevel,
122+
Repo: repo,
138123
}
139124

140125
data, err := json.MarshalIndent(metadata, "", " ")

0 commit comments

Comments
 (0)