From 57e43a230d92dff129791bce71a27848280c40b7 Mon Sep 17 00:00:00 2001 From: Seth Heidkamp <61526534+sheidkamp@users.noreply.github.com> Date: Thu, 14 Nov 2024 18:15:25 -0500 Subject: [PATCH] Update template_funcs.go (#567) --- changelog/v0.36.2/no-external-links.yaml | 6 ++++++ .../docgen/funcs/template_funcs.go | 9 ++++++++- pkg/code-generator/docgen/options/options.go | 19 +++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 changelog/v0.36.2/no-external-links.yaml diff --git a/changelog/v0.36.2/no-external-links.yaml b/changelog/v0.36.2/no-external-links.yaml new file mode 100644 index 000000000..984f45e22 --- /dev/null +++ b/changelog/v0.36.2/no-external-links.yaml @@ -0,0 +1,6 @@ +changelog: +- type: FIX + issueLink: https://github.com/solo-io/solo-projects/issues/6768 + resolvesIssue: false + description: >- + Update protobuf processing to no longer render links to locally hosted external API docs, as they are being removed. diff --git a/pkg/code-generator/docgen/funcs/template_funcs.go b/pkg/code-generator/docgen/funcs/template_funcs.go index 59d4063eb..847f2cc99 100644 --- a/pkg/code-generator/docgen/funcs/template_funcs.go +++ b/pkg/code-generator/docgen/funcs/template_funcs.go @@ -318,8 +318,15 @@ func linkForField(project *model.Project, docsOptions *options.DocsOptions) func linkedFile = filepath.Base(file.GetName()) //return "", errors.Errorf("failed to get generated file path for proto %v in list %v", file.GetName(), project.Request.FileToGenerate) } - linkedFile = relativeFilename(forFile.GetName(), linkedFile) + // Skip links for packages that are configured to be skipped + for _, pkg := range docsOptions.RenderOptions.GetSkipLinksForPathPrefixes() { + if strings.HasPrefix(linkedFile, pkg) { + return typeName, nil + } + } + + linkedFile = relativeFilename(forFile.GetName(), linkedFile) if docsOptions.Output == options.Restructured { linkText = ":ref:`message." + strings.TrimPrefix(field.GetTypeName(), ".") + "`" } else { diff --git a/pkg/code-generator/docgen/options/options.go b/pkg/code-generator/docgen/options/options.go index 27eda005c..29ef61941 100644 --- a/pkg/code-generator/docgen/options/options.go +++ b/pkg/code-generator/docgen/options/options.go @@ -21,8 +21,23 @@ type HugoOptions struct { } type DocsOptions struct { - Output DocsOutput - HugoOptions *HugoOptions + Output DocsOutput + HugoOptions *HugoOptions + RenderOptions *RenderOptions +} + +// RenderOptions provides options for rendering documentation +type RenderOptions struct { + // SkipLinksForPathPrefixes is a list of file path prefixes of APIs to which we should not be attempting to link + // For example: "github.com/solo-io/gloo/projects/gloo/api/external" + SkipLinksForPathPrefixes []string +} + +func (o *RenderOptions) GetSkipLinksForPathPrefixes() []string { + if o == nil { + return nil + } + return o.SkipLinksForPathPrefixes } const (