Skip to content

Commit ff12b53

Browse files
committed
OpenAPI: Move APIPage to fumadocs-openapi/ui
1 parent 7fcf612 commit ff12b53

File tree

10 files changed

+45
-13
lines changed

10 files changed

+45
-13
lines changed

.changeset/full-rabbits-stop.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'fumadocs-openapi': major
3+
---
4+
5+
**Move `APIPage` to `fumadocs-openapi/ui`**
6+
7+
migrate:
8+
9+
in your `mdx-components.tsx` (or where you pass MDX components):
10+
11+
```tsx
12+
import defaultComponents from 'fumadocs-ui/mdx';
13+
import { APIPage } from 'fumadocs-openapi/ui';
14+
import { openapi } from '@/lib/source';
15+
import type { MDXComponents } from 'mdx/types';
16+
17+
export function getMDXComponents(components?: MDXComponents): MDXComponents {
18+
return {
19+
...defaultComponents,
20+
// use this instead
21+
APIPage: (props) => <APIPage {...openapi.getAPIPageProps(props)} />,
22+
...components,
23+
};
24+
}
25+
```
26+
27+
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.

apps/docs/app/docs/[...slug]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { createGenerator } from 'fumadocs-typescript';
3535
import { getPageTreePeers } from 'fumadocs-core/server';
3636
import { Card, Cards } from 'fumadocs-ui/components/card';
3737
import { getMDXComponents } from '@/mdx-components';
38+
import { APIPage } from 'fumadocs-openapi/ui';
3839

3940
function PreviewRenderer({ preview }: { preview: string }): ReactNode {
4041
if (preview && preview in Preview) {
@@ -123,7 +124,7 @@ export default async function Page(props: {
123124
),
124125
Wrapper,
125126
blockquote: Callout as unknown as FC<ComponentProps<'blockquote'>>,
126-
APIPage: openapi.APIPage,
127+
APIPage: (props) => <APIPage {...openapi.getAPIPageProps(props)} />,
127128
DocsCategory: ({ url }) => {
128129
return <DocsCategory url={url ?? page.url} />;
129130
},

apps/docs/content/docs/ui/(integrations)/openapi/index.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ title: OpenAPI
33
description: Generating docs for OpenAPI schema
44
---
55

6-
You can setup Fumadocs OpenAPI manually, or use Fumadocs CLI.
7-
86
## Manual Setup
97

108
Install the required packages.
@@ -55,13 +53,14 @@ Add `APIPage` to your MDX Components, so that you can use it in MDX files.
5553

5654
```tsx title="mdx-components.tsx"
5755
import defaultComponents from 'fumadocs-ui/mdx';
56+
import { APIPage } from 'fumadocs-openapi/ui';
5857
import { openapi } from '@/lib/source';
5958
import type { MDXComponents } from 'mdx/types';
6059

6160
export function getMDXComponents(components?: MDXComponents): MDXComponents {
6261
return {
6362
...defaultComponents,
64-
APIPage: openapi.APIPage,
63+
APIPage: (props) => <APIPage {...openapi.getAPIPageProps(props)} />,
6564
...components,
6665
};
6766
}

examples/openapi/mdx-components.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import defaultMdxComponents from 'fumadocs-ui/mdx';
22
import type { MDXComponents } from 'mdx/types';
33
import { openapi } from '@/lib/source';
4+
import { APIPage } from 'fumadocs-openapi/ui';
45

56
export function getMDXComponents(components?: MDXComponents): MDXComponents {
67
return {
78
...defaultMdxComponents,
9+
APIPage: (props) => <APIPage {...openapi.getAPIPageProps(props)} />,
810
...components,
9-
APIPage: openapi.APIPage,
1011
};
1112
}

packages/openapi/src/build-routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Document } from '@/types';
22
import type { NoReference } from '@/utils/schema';
3-
import type { OperationItem, WebhookItem } from '@/server/api-page';
3+
import type { OperationItem, WebhookItem } from '@/render/api-page';
44
import type { OpenAPIV3_1 } from 'openapi-types';
55

66
export const methodKeys = [

packages/openapi/src/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { idToTitle } from '@/utils/id-to-title';
88
import type { OperationObject, PathItemObject } from './types';
99
import type { NoReference } from '@/utils/schema';
10-
import type { OperationItem, WebhookItem } from '@/server/api-page';
10+
import type { OperationItem, WebhookItem } from '@/render/api-page';
1111
import { type DocumentInput, processDocument } from '@/utils/process-document';
1212

1313
export interface GenerateOptions {
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { type FC } from 'react';
2-
import { APIPage, type ApiPageProps } from '@/server/api-page';
1+
import type { ApiPageProps } from '@/render/api-page';
32
import type { DocumentInput } from '@/utils/process-document';
43
import { createProxy } from '@/server/proxy';
54

@@ -12,15 +11,18 @@ export interface OpenAPIOptions
1211
}
1312

1413
export interface OpenAPIServer {
15-
APIPage: FC<ApiPageProps>;
14+
getAPIPageProps: (from: ApiPageProps) => ApiPageProps;
1615
createProxy: typeof createProxy;
1716
}
1817

1918
export function createOpenAPI(options: OpenAPIOptions = {}): OpenAPIServer {
2019
return {
2120
createProxy,
22-
APIPage(props) {
23-
return <APIPage {...options} {...props} />;
21+
getAPIPageProps(props) {
22+
return {
23+
...options,
24+
...props,
25+
};
2426
},
2527
};
2628
}

packages/openapi/src/ui/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ export function ObjectCollapsible(props: {
135135
</Collapsible>
136136
);
137137
}
138+
139+
export { APIPage, type ApiPageProps } from '@/render/api-page';

packages/openapi/src/utils/generate-document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
ApiPageProps,
77
OperationItem,
88
WebhookItem,
9-
} from '@/server/api-page';
9+
} from '@/render/api-page';
1010
import type { GenerateOptions } from '@/generate';
1111
import { idToTitle } from '@/utils/id-to-title';
1212
import type { Document, TagObject } from '@/types';

0 commit comments

Comments
 (0)