Scheduled broken-link and redirect checks that tell you the moment a link breaks — linkbruno.com
An OpenAPI file is documentation, a contract, and a source of links you will not see if you only crawl the marketing site. servers, externalDocs, OAuth token URLs, callback examples, termsOfService, markdown in description fields, and the "try it" target in a generated reference site all rot. I have seen a published API reference whose "Get API key" button pointed at a staging hostname for six months, because no HTML link checker was aimed at the spec.
Here is a script that pulls the URLs out of a spec and checks them.
Where URLs hide in a spec
Walk the JSON or YAML and you will find them in at least:
-
info.termsOfService,info.contact.url,info.license.url -
externalDocs.url(on the root, on tags, on operations) -
servers[].url(often a template likehttps://{region}.api.example.com) -
securitySchemesof typeoauth2oropenIdConnect(authorizationUrl,tokenUrl,openIdConnectUrl,refreshUrl) -
linksandcallbacks - markdown or HTML in
descriptionandsummaryfields (markdown links, and href attributes) - example request bodies and responses that contain URLs
-
$refto HTTP URLs, if you resolve external refs
A regex over the raw file will catch many of these and miss structured fields that are split across lines, or catch $ref: '#/components/...' which is not a link you should fetch. Walking the parsed document plus a markdown pass is more precise.
import json import re import sys from pathlib import Path from urllib.parse import urlparse import requests import yaml URL_RE = re.compile(r"https?://[^\s)\]}\"']+", re.I) SKIP_HOSTS = {"example.com", "localhost", "127.0.0.1"} # RFC 2606 reserved docs hosts often used in examples SKIP_SUFFIXES = (".example", ".example.com", ".invalid", ".test", ".localhost") def load_spec(path): text = Path(path).read_text() if path.endswith((".yaml", ".yml")): return yaml.safe_load(text), text return json.loads(text), text def values(obj): if isinstance(obj, dict): for v in obj.values(): yield from values(v) elif isinstance(obj, list): for v in obj: yield from values(v) elif isinstance(obj, str): yield obj def extract(spec, raw): found = set() for s in values(spec): if s.startswith("http://") or s.startswith("https://"): found.add(s.split()[0]) found.update(URL_RE.findall(s)) found.update(URL_RE.findall(raw)) return sorted(found) def should_skip(url): host = urlparse(url).hostname or "" if host in SKIP_HOSTS or any(host.endswith(s) for s in SKIP_SUFFIXES): return True if "{" in url or "}" in url: return True # templated server URL; handle separately if you need to return False def check(url): try: r = requests.get(url, timeout=15, allow_redirects=True) return r.status_code, r.url except requests.RequestException as e: return type(e).__name__, "" if __name__ == "__main__": spec, raw = load_spec(sys.argv[1]) for url in extract(spec, raw): if should_skip(url): print(f"SKIP\t{url}") continue status, final = check(url) flag = "OK" if status == 200 else "FAIL" print(f"{flag}\t{status}\t{url}\t{final}") What to skip, and what not to
Skip obvious example hosts (example.com, .test, documentation-only placeholders). You do not want CI to fail because https://example.com/callback in a sample payload is not a real server.
Do not skip your own docs host, your dashboard, or your production API if the spec claims they are real. Those are the ones that break when a docs page is renamed or a marketing site move forgets /developers.
Templated server URLs (https://{region}.api.example.com) cannot be fetched as-is. Either expand them with known regions, or check a documented concrete example (https://us.api.example.com) and skip the template.
Auth-protected endpoints will 401. For those, a 401 or 403 from the right host is often success; a 404 or a DNS error is not. Treat status classes by URL prefix so the checker doesn't demand a 200 from /v1/me.
Run it where the spec is built
Hook the script into the same CI job that lints the OpenAPI file. Fail the build on FAIL for any URL whose host is on an allowlist of your properties (docs, dashboard, marketing, the production API). Warn-only for third-party URLs if you don't want a dead partner site to block a release, but still log them.
Then, once the reference site is generated (Redoc, Stoplight, Swagger UI, a custom site), run a normal HTML link check on the output as well. The spec can be clean while the generated template points "Download OpenAPI" at a stale path, or while the Try-it-out server is hardcoded to localhost in production.
A published API reference is a website full of links, even if the source is a YAML file nobody crawls. linkbruno.com can keep checking the live docs and the URLs they point to on a schedule, so a renamed guide or a retired dashboard path shows up before a customer hits it from the "Get started" button.
Descriptions are markdown, and they rot like blog posts
A lot of the worst links in a spec are not in structured fields. They are in description on an operation: "see the rate limits guide at https://docs.example.com/old-path", "download the CSV template", "if you get 401, reset your key at the dashboard URL". When the docs site is reorganized, these are the last things anyone updates, because they do not fail a schema linter.
The script above already extracts them with a regex over every string. Worth a second pass: render the descriptions to HTML (your generator already does) and run the HTML checker on that output. Markdown that doesn't quite match the regex — reference-style links, autolinked bare URLs, links broken across a line wrap in YAML folded scalars — shows up once it's HTML.
If you keep screenshots or images in the repo and reference them from descriptions, check those paths too. A ../../assets/auth-flow.png that moved is as broken as a 404 on a guide.
A small extra: server URLs in "try it out"
If your generated docs let people fire real requests, the servers entry they will hit is the most important link in the file. Point it at production only if you mean to, and never at a personal staging tunnel. I like a CI assertion: every servers[].url is in a short allowlist, and none of them contain ngrok, localhost, or a preview hostname.
Related reading
- Changing your URL structure (or adding a locale prefix like /en/)? A 12-point checklist so old links keep working
- How to check every link in your npm package before you publish (README, homepage, repository and bugs)
- How to check links with lychee in GitHub Actions (config, caching, and the false positives to exclude)
- How to find broken #anchor links, the ones every link checker says are fine
Have you shipped a spec with a staging URL in servers or a dead externalDocs link? How long was it live before someone noticed?