Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update template_funcs.go #567

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/v0.36.2/no-external-links.yaml
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 8 additions & 1 deletion pkg/code-generator/docgen/funcs/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions pkg/code-generator/docgen/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down