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 type { ReactNode } from 'react'; |
| 2 | import type { TOCItemType } from 'fumadocs-core/toc'; |
| 3 | import type { OpenAPIPageProps } from 'fumadocs-openapi/ui'; |
| 4 | import { z } from 'zod'; |
| 5 | import type { OpenApiSchemaPageData } from '@/lib/api-deprecation'; |
| 6 | import type { ReferenceMdxPageData } from '@/lib/source'; |
| 7 | |
| 8 | // The combined reference source mixes MDX and fumadocs-openapi pages, so page |
| 9 | // data is parsed once against the shape each renderer needs instead of being |
| 10 | // narrowed with `in` guards and casts. Function-valued members use z.custom |
| 11 | // with a typeof check because zod cannot otherwise validate functions. |
| 12 | export const openApiReferencePageDataSchema = z.object({ |
| 13 | title: z.string(), |
| 14 | getOpenAPIPageProps: z.custom<() => OpenAPIPageProps>(value => typeof value === 'function'), |
| 15 | getSchema: z.custom<OpenApiSchemaPageData['getSchema']>(value => typeof value === 'function'), |
| 16 | }); |
| 17 | |
| 18 | // A TOC entry's `title` is a ReactNode, which admits nearly any runtime value |
| 19 | // (string, number, element, fragment, null, ...), so it is not runtime-checkable; |
| 20 | // the structural fields are validated. looseObject keeps extra members such as |
| 21 | // remark-steps' `_step` intact. |
| 22 | const tocItemSchema: z.ZodType<TOCItemType> = z.looseObject({ |
| 23 | title: z.custom<ReactNode>(() => true), |
| 24 | url: z.string(), |
| 25 | depth: z.number(), |
| 26 | }); |
| 27 | |
| 28 | export const referenceMdxPageDataSchema = z.object({ |
| 29 | title: z.string(), |
| 30 | full: z.boolean().optional().catch(undefined), |
| 31 | toc: z.array(tocItemSchema), |
| 32 | body: z.custom<ReferenceMdxPageData['body']>(value => typeof value === 'function'), |
| 33 | }); |