Files
Alberto Schiabel 3335bb3013 fix(docs): restore API reference pages dropped by undeclared tags (#3973)
This PR:

- fixes a regression introduced by
https://github.com/ComposioHQ/composio/pull/3956: fumadocs-openapi 11's
`groupBy: 'tag'` silently skips operations whose tag is not declared in
the document's top-level `tags` array, which 404'd all 16 Projects and
Organization Management operation pages (e.g.
`/reference/api-reference/projects/postProjectUsageSummary`) on both
v3.1 and v3, and dropped them from the sitemap and search index
- adds `declareOperationTags()` (`docs/lib/openapi-tags.ts`), applied at
spec load time in `lib/openapi.ts` (covers build-time-fetched specs) and
at sync time in `scripts/fetch-openapi.mjs`, which now also warns when
the upstream payload omits tags; the checked-in specs are normalized
accordingly (purely additive)
- adds CI guards in `tests/static/api-reference-routes.test.ts`: spec
invariants (every visible operation has a tag and `operationId`),
bidirectional spec-vs-generated-routes set equality through the
production loader path, a negative test pinning fumadocs' silent-drop
behavior (fails when upstream fixes it, signaling the workaround can be
retired), and validation that every `ApiEndpointsTable` quick-link href
resolves to a generated page
- extends `Docs - Check Links` with a nightly (02:30 UTC) + manual
external-URL sweep via a new `lint:links:external` script; the validator
only fails on evidence a link is dead (404/410 or repeated network
errors, with UA/timeout/GET-fallback/retry and per-URL caching) and
scheduled failures file a deduplicated tracking issue; PR runs keep the
fast internal-only check
- fixes six dead external links the first sweep found (moved Claude
Agent SDK docs, stale dashboard settings URL ×2, a `master`-branch path
now pinned to tag `0.5.0+post.1`, and two removed `ComposioHQ` example
repos whose mentions were dropped — their code is embedded in the pages
via `RepoBrowser`)

## Context

fumadocs-openapi 10 generated a page for any tag string found on an
operation; v11 requires the tag to be declared top-level and skips
silently otherwise (`preset-auto.js`: `builder.fromTagName(tag)` →
`continue`, no warning). The backend spec generator omits `Projects`,
`Organization Management`, and `Invite Codes` from `tags`, so their
operation pages vanished while the checked-in MDX tag landing pages kept
rendering with dead quick links. With the normalizer, the generated URL
set is byte-identical to the pre-#3956 set (234 routes, verified via
`getReferenceSource().getPages()` diff); no revert needed.

Existing checks missed this because `lint:links` only extracts markdown
links and `Card` hrefs (the dead links live in `ApiEndpointsTable`'s
array prop) and validates against the same loader that shrank, and the
integration suite samples fixed routes under tags that survived. The new
completeness guard derives expectations from the specs themselves, so
routine data syncs don't churn it.
2026-07-29 03:05:43 +05:30

55 lines
1.9 KiB
TypeScript

import { readFile } from 'node:fs/promises';
import { join } from 'path';
import { createOpenAPI } from 'fumadocs-openapi/server';
import { declareOperationTags, type OpenAPIDocument } from './openapi-tags';
export { declareOperationTags } from './openapi-tags';
const openapiPath = join(process.cwd(), 'public/openapi.json');
const openapiWebhooksPath = join(
process.cwd(),
'public/openapi-webhooks.json',
);
const openapiV3Path = join(process.cwd(), 'public/openapi-v3.json');
// v3.1 (latest) — clean operationIds, default API reference.
// The webhook-events spec (openapi-webhooks.json) is a separate OpenAPI 3.1
// document whose top-level `webhooks` block documents the payloads Composio
// delivers to customer webhook URLs; it renders under the "Webhook Events" tag.
export const openapi = createOpenAPI({
input: {
[openapiPath]: () => loadOpenAPISchema(openapiPath),
[openapiWebhooksPath]: () => loadOpenAPISchema(openapiWebhooksPath),
},
proxyUrl: '/api/proxy',
});
// v3.0 — mounted under api-reference/v3/
export const openapiV3 = createOpenAPI({
input: {
[openapiV3Path]: () => loadOpenAPISchema(openapiV3Path),
},
proxyUrl: '/api/proxy',
});
async function loadOpenAPISchema(path: string) {
const document = JSON.parse(await readFile(path, 'utf8')) as OpenAPIDocument;
return declareOperationTags(normalizeNoAuthSecurity(document));
}
export function normalizeNoAuthSecurity<T extends OpenAPIDocument>(document: T): T {
// The backend generator uses `{ no_auth: [] }` as a legacy sentinel for
// public operations. It is not a declared security scheme, so remove that
// alternative while preserving any declared schemes.
for (const pathItem of Object.values(document.paths ?? {})) {
for (const operation of Object.values(pathItem)) {
if (!operation?.security) continue;
operation.security = operation.security.filter(
(requirement) => !('no_auth' in requirement),
);
}
}
return document;
}