OpenAPI: Move APIPage to fumadocs-openapi/ui

This commit is contained in:
Fuma Nama
2025-04-10 20:04:01 +08:00
parent 7fcf612179
commit ff12b53268
10 changed files with 45 additions and 13 deletions
+27
View File
@@ -0,0 +1,27 @@
---
'fumadocs-openapi': major
---
**Move `APIPage` to `fumadocs-openapi/ui`**
migrate:
in your `mdx-components.tsx` (or where you pass MDX components):
```tsx
import defaultComponents from 'fumadocs-ui/mdx';
import { APIPage } from 'fumadocs-openapi/ui';
import { openapi } from '@/lib/source';
import type { MDXComponents } from 'mdx/types';
export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...defaultComponents,
// use this instead
APIPage: (props) => <APIPage {...openapi.getAPIPageProps(props)} />,
...components,
};
}
```
why: Next.js compiles the same module in different layers: route handlers, pages (which include browser bundle), and middleware (Edge Runtime). It avoids compiling React components of `fumadocs-openapi` twice when you reference the OpenAPI server in a route handler.
+2 -1
View File
@@ -35,6 +35,7 @@ import { createGenerator } from 'fumadocs-typescript';
import { getPageTreePeers } from 'fumadocs-core/server';
import { Card, Cards } from 'fumadocs-ui/components/card';
import { getMDXComponents } from '@/mdx-components';
import { APIPage } from 'fumadocs-openapi/ui';
function PreviewRenderer({ preview }: { preview: string }): ReactNode {
if (preview && preview in Preview) {
@@ -123,7 +124,7 @@ export default async function Page(props: {
),
Wrapper,
blockquote: Callout as unknown as FC<ComponentProps<'blockquote'>>,
APIPage: openapi.APIPage,
APIPage: (props) => <APIPage {...openapi.getAPIPageProps(props)} />,
DocsCategory: ({ url }) => {
return <DocsCategory url={url ?? page.url} />;
},
@@ -3,8 +3,6 @@ title: OpenAPI
description: Generating docs for OpenAPI schema
---
You can setup Fumadocs OpenAPI manually, or use Fumadocs CLI.
## Manual Setup
Install the required packages.
@@ -55,13 +53,14 @@ Add `APIPage` to your MDX Components, so that you can use it in MDX files.
```tsx title="mdx-components.tsx"
import defaultComponents from 'fumadocs-ui/mdx';
import { APIPage } from 'fumadocs-openapi/ui';
import { openapi } from '@/lib/source';
import type { MDXComponents } from 'mdx/types';
export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...defaultComponents,
APIPage: openapi.APIPage,
APIPage: (props) => <APIPage {...openapi.getAPIPageProps(props)} />,
...components,
};
}
+2 -1
View File
@@ -1,11 +1,12 @@
import defaultMdxComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from 'mdx/types';
import { openapi } from '@/lib/source';
import { APIPage } from 'fumadocs-openapi/ui';
export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...defaultMdxComponents,
APIPage: (props) => <APIPage {...openapi.getAPIPageProps(props)} />,
...components,
APIPage: openapi.APIPage,
};
}
+1 -1
View File
@@ -1,6 +1,6 @@
import { type Document } from '@/types';
import type { NoReference } from '@/utils/schema';
import type { OperationItem, WebhookItem } from '@/server/api-page';
import type { OperationItem, WebhookItem } from '@/render/api-page';
import type { OpenAPIV3_1 } from 'openapi-types';
export const methodKeys = [
+1 -1
View File
@@ -7,7 +7,7 @@ import {
import { idToTitle } from '@/utils/id-to-title';
import type { OperationObject, PathItemObject } from './types';
import type { NoReference } from '@/utils/schema';
import type { OperationItem, WebhookItem } from '@/server/api-page';
import type { OperationItem, WebhookItem } from '@/render/api-page';
import { type DocumentInput, processDocument } from '@/utils/process-document';
export interface GenerateOptions {
+7 -5
View File
@@ -1,5 +1,4 @@
import { type FC } from 'react';
import { APIPage, type ApiPageProps } from '@/server/api-page';
import type { ApiPageProps } from '@/render/api-page';
import type { DocumentInput } from '@/utils/process-document';
import { createProxy } from '@/server/proxy';
@@ -12,15 +11,18 @@ export interface OpenAPIOptions
}
export interface OpenAPIServer {
APIPage: FC<ApiPageProps>;
getAPIPageProps: (from: ApiPageProps) => ApiPageProps;
createProxy: typeof createProxy;
}
export function createOpenAPI(options: OpenAPIOptions = {}): OpenAPIServer {
return {
createProxy,
APIPage(props) {
return <APIPage {...options} {...props} />;
getAPIPageProps(props) {
return {
...options,
...props,
};
},
};
}
+2
View File
@@ -135,3 +135,5 @@ export function ObjectCollapsible(props: {
</Collapsible>
);
}
export { APIPage, type ApiPageProps } from '@/render/api-page';
@@ -6,7 +6,7 @@ import type {
ApiPageProps,
OperationItem,
WebhookItem,
} from '@/server/api-page';
} from '@/render/api-page';
import type { GenerateOptions } from '@/generate';
import { idToTitle } from '@/utils/id-to-title';
import type { Document, TagObject } from '@/types';