Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { readFile } from 'node:fs/promises'; |
| 2 | import { join } from 'path'; |
| 3 | import { createOpenAPI } from 'fumadocs-openapi/server'; |
| 4 | import { declareOperationTags, type OpenAPIDocument } from './openapi-tags'; |
| 5 | |
| 6 | export { declareOperationTags } from './openapi-tags'; |
| 7 | |
| 8 | const openapiPath = join(process.cwd(), 'public/openapi.json'); |
| 9 | const openapiWebhooksPath = join( |
| 10 | process.cwd(), |
| 11 | 'public/openapi-webhooks.json', |
| 12 | ); |
| 13 | const openapiV3Path = join(process.cwd(), 'public/openapi-v3.json'); |
| 14 | |
| 15 | // v3.1 (latest) — clean operationIds, default API reference. |
| 16 | // The webhook-events spec (openapi-webhooks.json) is a separate OpenAPI 3.1 |
| 17 | // document whose top-level `webhooks` block documents the payloads Composio |
| 18 | // delivers to customer webhook URLs; each of its tags (e.g. "Webhook Events") |
| 19 | // renders as its own section. |
| 20 | export const openapi = createOpenAPI({ |
| 21 | input: { |
| 22 | [openapiPath]: () => loadOpenAPISchema(openapiPath), |
| 23 | [openapiWebhooksPath]: () => loadOpenAPISchema(openapiWebhooksPath), |
| 24 | }, |
| 25 | proxyUrl: '/api/proxy', |
| 26 | }); |
| 27 | |
| 28 | // v3.0 — mounted under api-reference/v3/ |
| 29 | export const openapiV3 = createOpenAPI({ |
| 30 | input: { |
| 31 | [openapiV3Path]: () => loadOpenAPISchema(openapiV3Path), |
| 32 | }, |
| 33 | proxyUrl: '/api/proxy', |
| 34 | }); |
| 35 | |
| 36 | async function loadOpenAPISchema(path: string) { |
| 37 | const document = JSON.parse(await readFile(path, 'utf8')) as OpenAPIDocument; |
| 38 | return declareOperationTags(normalizeNoAuthSecurity(document)); |
| 39 | } |
| 40 | |
| 41 | export function normalizeNoAuthSecurity<T extends OpenAPIDocument>(document: T): T { |
| 42 | // The backend generator uses `{ no_auth: [] }` as a legacy sentinel for |
| 43 | // public operations. It is not a declared security scheme, so remove that |
| 44 | // alternative while preserving any declared schemes. |
| 45 | for (const pathItem of Object.values(document.paths ?? {})) { |
| 46 | for (const operation of Object.values(pathItem)) { |
| 47 | if (!operation?.security) continue; |
| 48 | operation.security = operation.security.filter( |
| 49 | (requirement) => !('no_auth' in requirement), |
| 50 | ); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return document; |
| 55 | } |