Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b2bbe8d
Warn when links to the API docs point at pages that do not exist
akira28 Nov 2, 2026
c4dcaac
Report API links in redirects.yml against the redirects file
akira28 Nov 2, 2026
cb684bf
Collapse duplicate slashes in API links and write the report without …
akira28 Nov 2, 2026
5115e19
Merge remote-tracking branch 'origin/main' into feature/request-link-…
akira28 Nov 3, 2026
616bd05
Record API links with the outbound link extractor instead of parse hooks
akira28 Nov 3, 2026
ecabff4
Address review: record API links where links are parsed, fix preview …
akira28 Nov 3, 2026
5cf92e9
Resolve old bump.sh API URLs through the edge redirects before checking
akira28 Nov 3, 2026
4c2a6bf
Record angle-bracket API autolinks and skip API links inside comments
akira28 Nov 4, 2026
ae861f3
Fix the angle-bracket autolink test base
akira28 Nov 4, 2026
4a67d21
Merge branch 'main' into feature/request-link-checking-related
akira28 Nov 4, 2026
25808cf
Merge branch 'main' into feature/request-link-checking-related
Mpdreamz Nov 4, 2026
ed50b61
Check links inside API descriptions against the generated pages
akira28 Nov 5, 2026
b115859
Merge remote-tracking branch 'origin/feature/request-link-checking-re…
akira28 Nov 5, 2026
103108d
Merge main and check API links through the cross-link resolver
akira28 Nov 6, 2026
20aa058
Document the API link warning next to API cross-links
akira28 Nov 6, 2026
1c0e72d
Address review: dedupe description links, skip changelogs, warn on go…
akira28 Nov 6, 2026
13a0a46
Report redirect API links against the redirects file and fix the docs
akira28 Nov 6, 2026
42765e3
Report missing API pages as a suppressible hint so strict builds pass
akira28 Nov 6, 2026
1f56535
Merge branch 'main' into feature/request-link-checking-related
akira28 Nov 9, 2026
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
7 changes: 6 additions & 1 deletion docs/documentation/isolated/configure/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ suppress:
- DeepLinkingVirtualFile
- FolderFileNameMismatch
- AutolinkElasticCoDocs
- ApiLinkMissingPage
```

### Scope
Expand All @@ -214,7 +215,7 @@ Where you put `suppress` decides which navigation entries it covers:
- In `docset.yml`, the list applies to the entries declared in `docset.yml` itself.
- In a nested `toc.yml`, the list applies only to the entries in that `toc.yml`. It doesn't carry over to `docset.yml` or to other `toc.yml` files, and a `toc.yml` doesn't inherit the list from `docset.yml`.

`AutolinkElasticCoDocs` is raised while Markdown is parsed, so it's only read from `docset.yml` and applies to every page in the docset.
`AutolinkElasticCoDocs` and `ApiLinkMissingPage` are raised while Markdown is parsed, so they're only read from `docset.yml` and apply to every page in the docset.

### `DeepLinkingVirtualFile`

Expand All @@ -234,3 +235,7 @@ Suppresses hints about file names not matching folder names in a `folder:` with
### `AutolinkElasticCoDocs`

Suppresses hints about bare URLs pointing to elastic.co/docs. Prefer cross-links or relative links. Only valid in `docset.yml`.

### `ApiLinkMissingPage`

Suppresses hints about links to API reference pages that don't exist in the API pages of the link index. Prefer fixing the link or using an API cross-link. Only valid in `docset.yml`.
10 changes: 10 additions & 0 deletions docs/syntax/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ Link to websites and resources outside the Elastic docs:

External links display an arrow indicator next to the link text.

### Links to API reference pages

Prefer an [API cross-link](../data/openapi/api-explorer.md#api-cross-links) to an API page, because the build fails when the page is missing. A hard-coded `https://www.elastic.co/docs/api/doc/...` link still works, and the build shows a hint when it points at a page that no longer exists in the API pages of the link index. The hint doesn't fail a `--strict` build, and you can silence it with `ApiLinkMissingPage` under [`suppress`](../documentation/isolated/configure/index.md#suppress). It covers inline links, bare URLs, directive links, `redirects.yml` targets and the links between API pages in OpenAPI descriptions, which you fix in the spec.

```markdown
[Search API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search)
```

If an endpoint no longer exists in the current API docs, point the link at the versioned tree that still has it, for example `https://www.elastic.co/docs/api/doc/kibana/v8/...`. Only the page is checked, not the `#anchor`, and `<...>` autolinks are not checked. An API the link index holds no pages for is not checked. Old bump.sh URLs are checked at the page the edge redirects them to.

### Linked images

Wrap an image in a link to make the image itself clickable. Combine the image syntax with the link syntax:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public record ConfigurationFile

public Dictionary<string, LinkRedirect>? Redirects { get; }

public IFileInfo? RedirectsSource { get; }

public HashSet<Product> Products { get; private set; } = [];

private readonly Dictionary<string, string> _substitutions = [with(StringComparer.OrdinalIgnoreCase)];
Expand Down Expand Up @@ -138,6 +140,7 @@ ProductsConfiguration productsConfig

var redirectFile = new RedirectFile(_context);
Redirects = redirectFile.Redirects;
RedirectsSource = redirectFile.Source;

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class TableOfContentsFile
/// <summary>
/// Set of diagnostic hint types to suppress for the entries in this table of contents.
/// Deserialized directly from YAML list of strings.
/// Valid values: "DeepLinkingVirtualFile", "FolderFileNameMismatch", "AutolinkElasticCoDocs"
/// (the latter is only honoured from <c>docset.yml</c>).
/// Valid values: "DeepLinkingVirtualFile", "FolderFileNameMismatch", "AutolinkElasticCoDocs", "ApiLinkMissingPage"
/// (the last two are only honoured from <c>docset.yml</c>).
/// </summary>
[YamlPropertyName("suppress")]
public HashSet<HintType> SuppressDiagnostics { get; set; } = [];
Expand Down
36 changes: 36 additions & 0 deletions src/Elastic.Documentation.Links/CrossLinks/ApiLinkCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Documentation.Diagnostics;

namespace Elastic.Documentation.Links.CrossLinks;

/// <summary>Checks a link to an API reference page against the API sections the cross-link resolver holds.</summary>
public static class ApiLinkCheck
{
/// <summary>
/// Returns a hint when <paramref name="url"/> targets an API page that the resolver knows does not exist, and
/// <c>null</c> for any other link, and for an API it holds no section for. A link to a root with no pages at all always hints. Old bump.sh URLs are checked at the
/// page the edge redirects them to.
/// </summary>
public static string? GetHint(ICrossLinkResolver resolver, string? url, string? urlPathPrefix, HashSet<HintType>? suppressions)
{
if (suppressions.ShouldSuppress(HintType.ApiLinkMissingPage))
return null;

if (
!ApiLinkMatcher.TryCanonicalize(url, urlPathPrefix, out var canonical) || !ApiLinkMatcher.TryGetApiPath(canonical, out var path)
)
return null;

// The spec downloads next to a product root, kibana.json and kibana.yaml, are files, not pages of its section.
if (Path.GetExtension(path) is ".json" or ".yaml")
return null;

return ApiLegacyRedirects.IsGone(path) || resolver.CheckApiPage(ApiLegacyRedirects.Resolve(path)) == ApiPageStatus.Missing
? $"API link '{canonical}' does not resolve to a page of that API. Link to a page that exists, such as one in a versioned tree like "
+ "/docs/api/doc/<product>/v8/..., or confirm the endpoint was removed intentionally. Links in API descriptions are fixed in the OpenAPI spec."
: null;
}
}
34 changes: 34 additions & 0 deletions src/Elastic.Documentation.Links/CrossLinks/CrossLinkResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ public interface ICrossLinkResolver
/// protocol links and pass through without cross-link validation.
/// </summary>
bool IsDeclaredCrossLinkScheme(string scheme);

/// <summary>
/// Whether the API page at <paramref name="sitePath"/>, a path from the site root such as
/// <c>/docs/api/doc/elasticsearch/operation/operation-search</c>, exists in the API sections of the link index.
/// A resolver that holds no section for that API cannot tell, and answers <see cref="ApiPageStatus.Unknown"/>.
/// </summary>
ApiPageStatus CheckApiPage(string sitePath) => ApiPageStatus.Unknown;
}

public enum ApiPageStatus
{
/// <summary>No API section covers the path, so the page cannot be judged.</summary>
Unknown,
Exists,
Missing
}

public class NoopCrossLinkResolver : ICrossLinkResolver
Expand Down Expand Up @@ -53,6 +68,25 @@ public bool TryResolve(Action<string> errorEmitter, Uri crossLinkUri, [NotNullWh
/// <inheritdoc />
public bool IsDeclaredCrossLinkScheme(string scheme) => _crossLinks.DeclaredRepositories.Contains(scheme);

/// <inheritdoc />
public ApiPageStatus CheckApiPage(string sitePath)
{
// API keys are unique across a build, so the key in the path names the one section that can hold the page.
var path = sitePath.Trim('/');
var rest = path.StartsWith("docs/", StringComparison.Ordinal) ? path["docs/".Length..] : path;
if (!rest.StartsWith("api/doc/", StringComparison.Ordinal))
return ApiPageStatus.Unknown;

var key = rest["api/doc/".Length..].Split('/', 2)[0];
foreach (var links in _crossLinks.LinkReferences.Values)
{
if (links.Floating is { Count: > 0 } floating && floating.TryGetValue($"api/{key}", out var section))
return section.ContainsSitePath(rest) ? ApiPageStatus.Exists : ApiPageStatus.Missing;
}

return ApiPageStatus.Unknown;
}

public FetchedCrossLinks UpdateLinkReference(string repository, RepositoryLinks repositoryLinks)
{
var dictionary = _crossLinks.LinkReferences.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Expand Down
67 changes: 67 additions & 0 deletions src/Elastic.Documentation/Diagnostics/ApiLinkMatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Text.RegularExpressions;

namespace Elastic.Documentation.Diagnostics;

public static partial class ApiLinkMatcher
{
public const string ApiDocPrefix = "/docs/api/doc/";

/// <summary>
/// Returns the normalized page path (no query, fragment or trailing slash, lowercase) when
/// <paramref name="url"/> targets an API reference page on elastic.co.
/// </summary>
public static bool TryGetApiPath(string? url, out string path)
{
path = string.Empty;
if (string.IsNullOrWhiteSpace(url) || !Uri.TryCreate(url.Trim(), UriKind.Absolute, out var uri))
return false;
if (uri.Scheme is not ("http" or "https"))
return false;
if (
!uri.Host.Equals("www.elastic.co", StringComparison.OrdinalIgnoreCase)
&& !uri.Host.Equals("elastic.co", StringComparison.OrdinalIgnoreCase)
)
return false;

var normalized = Normalize(uri.AbsolutePath);
if (!normalized.StartsWith(ApiDocPrefix, StringComparison.Ordinal))
return false;

path = normalized;
return true;
}

/// <summary>
/// Returns <paramref name="url"/> as an absolute elastic.co API URL when it targets an API page, either as such or as a
/// site path under <paramref name="urlPathPrefix"/>, which is how the API Explorer writes links between its own pages.
/// </summary>
public static bool TryCanonicalize(string? url, string? urlPathPrefix, out string canonical)
{
canonical = string.Empty;
if (string.IsNullOrWhiteSpace(url))
return false;

if (TryGetApiPath(url, out _))
{
canonical = url;
return true;
}

var prefix = urlPathPrefix?.TrimEnd('/') ?? string.Empty;
if (!url.StartsWith($"{prefix}/api/doc/", StringComparison.OrdinalIgnoreCase))
return false;

canonical = $"https://www.elastic.co/docs{url[prefix.Length..]}";
return true;
}

public static string Normalize(string path) =>
DuplicateSlashes().Replace(Uri.UnescapeDataString(path), "/").TrimEnd('/').ToLowerInvariant();

[GeneratedRegex("/{2,}")]
private static partial Regex DuplicateSlashes();
}
7 changes: 6 additions & 1 deletion src/Elastic.Documentation/Diagnostics/HintType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ public enum HintType
/// <summary>
/// Hint about autolinks pointing to elastic.co/docs that should use crosslinks or relative links instead.
/// </summary>
AutolinkElasticCoDocs
AutolinkElasticCoDocs,

/// <summary>
/// Hint about a link to an API reference page that does not exist in the API pages of the link index.
/// </summary>
ApiLinkMissingPage
}
77 changes: 77 additions & 0 deletions src/Elastic.Documentation/Links/ApiLegacyRedirects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Documentation.Diagnostics;

namespace Elastic.Documentation.Links;

/// <summary>
/// The redirects from old bump.sh API URLs. They mirror <c>modules/elastic-docs-v3/api-root-redirects.json</c> in
/// elastic/docs-infra (#459), which the native viewer resolves exact match first. Keep this table in sync with that file.
/// </summary>
// TODO: Delete this class once the API Explorer migration (elastic/docs-eng-team#436) is finalised.
public static class ApiLegacyRedirects
{
private static readonly IReadOnlyDictionary<string, string> RedirectedRoots = new Dictionary<string, string>
{
["serverless"] = "kibana-serverless",
["elastic-cloud-serverless"] = "cloud-serverless"
};

private static readonly IReadOnlySet<string> GoneRoots = new HashSet<string> { "observability-serverless" };

// Exact page redirects from the same file. Bump.sh served a Servers page for specs that declare no servers,
// Cloud Billing renamed its Budgets tag, Kibana removed Streams operations from its 9.6 spec, and some bump.sh topic
// pages are a children: page or the /authentication page in the native viewer.
private static readonly IReadOnlyDictionary<string, string> RedirectedPages = new Dictionary<string, string>
{
["/docs/api/doc/elasticsearch/servers"] = "/docs/api/doc/elasticsearch",
["/docs/api/doc/elasticsearch/v8/servers"] = "/docs/api/doc/elasticsearch/v8",
["/docs/api/doc/elasticsearch/v9/servers"] = "/docs/api/doc/elasticsearch/v9",
["/docs/api/doc/elasticsearch-serverless/servers"] = "/docs/api/doc/elasticsearch-serverless",
["/docs/api/doc/cloud-enterprise/servers"] = "/docs/api/doc/cloud-enterprise",
["/docs/api/doc/cloud-enterprise/v3/servers"] = "/docs/api/doc/cloud-enterprise/v3",
["/docs/api/doc/cloud-billing/group/endpoint-budgets"] = "/docs/api/doc/cloud-billing/group/endpoint-billing-budgets",
["/docs/api/doc/kibana/topic/topic-kibana-spaces"] = "/docs/api/doc/kibana/kibana-api-overview",
["/docs/api/doc/kibana/v8/topic/topic-kibana-spaces"] = "/docs/api/doc/kibana/v8/kibana-api-overview",
["/docs/api/doc/kibana/v9/topic/topic-kibana-spaces"] = "/docs/api/doc/kibana/v9/kibana-api-overview",
["/docs/api/doc/cloud/topic/topic-authentication"] = "/docs/api/doc/cloud/authentication",
["/docs/api/doc/cloud-billing/topic/topic-authentication"] = "/docs/api/doc/cloud-billing/authentication",
["/docs/api/doc/kibana/v9/group/endpoint-significant_events"] = "/docs/api/doc/kibana/v9/group/endpoint-streams",
["/docs/api/doc/kibana/v9/operation/operation-delete-streams-name-queries-queryid"] =
"/docs/api/doc/kibana/v9/group/endpoint-streams",
["/docs/api/doc/kibana/v9/operation/operation-get-streams-name-queries"] = "/docs/api/doc/kibana/v9/group/endpoint-streams",
["/docs/api/doc/kibana/v9/operation/operation-get-streams-name-significant-events"] =
"/docs/api/doc/kibana/v9/group/endpoint-streams",
["/docs/api/doc/kibana/v9/operation/operation-post-streams-name-queries-bulk"] = "/docs/api/doc/kibana/v9/group/endpoint-streams",
["/docs/api/doc/kibana/v9/operation/operation-put-streams-name-queries-queryid"] = "/docs/api/doc/kibana/v9/group/endpoint-streams"
};

/// <summary>True for a root with no pages at all, so a link to it has nowhere to land.</summary>
public static bool IsGone(string path) => GoneRoots.Contains(RootOf(path));

/// <summary>True when the edge redirects this path to another one.</summary>
public static bool IsRedirected(string path) => RedirectedPages.ContainsKey(path) || RedirectedRoots.ContainsKey(RootOf(path));

/// <summary>The path the edge serves for <paramref name="path"/>: its redirect target, or the path itself.</summary>
public static string Resolve(string path)
{
if (RedirectedPages.TryGetValue(path, out var page))
return page;

var root = RootOf(path);
return RedirectedRoots.TryGetValue(root, out var newRoot)
? string.Concat(ApiLinkMatcher.ApiDocPrefix, newRoot, path.AsSpan(ApiLinkMatcher.ApiDocPrefix.Length + root.Length))
: path;
}

private static string RootOf(string path)
{
if (!path.StartsWith(ApiLinkMatcher.ApiDocPrefix, StringComparison.Ordinal))
return string.Empty;
var rest = path[ApiLinkMatcher.ApiDocPrefix.Length..];
var slash = rest.IndexOf('/');
return slash < 0 ? rest : rest[..slash];
}
}
24 changes: 24 additions & 0 deletions src/Elastic.Documentation/Links/FloatingLinkSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,28 @@ public bool TryResolvePage(string? version, string page, out string sitePath)
sitePath = page.Length == 0 ? root : $"{root}/{page}";
return true;
}

/// <summary>
/// Whether <paramref name="sitePath"/>, a path from the site root without slashes at either end, is a page of any
/// version of this section, directly or through an alias. It matches the longest version root first, so the
/// page of a versioned tree is never read as a page of the current version.
/// </summary>
public bool ContainsSitePath(string sitePath)
{
foreach (var version in Versions.OrderByDescending(v => v.Root.Length))
{
string page;
if (sitePath.Equals(version.Root, StringComparison.Ordinal))
page = string.Empty;
else if (sitePath.StartsWith(version.Root + "/", StringComparison.Ordinal))
page = sitePath[(version.Root.Length + 1)..];
else
continue;

if (TryResolvePage(version.Name, page, out _))
return true;
}

return false;
}
}
Loading
Loading