Skip to content

Commit 046fa2b

Browse files
committed
OpenAPI: require passing <APIPage />
1 parent e028a3d commit 046fa2b

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

.changeset/thirty-jobs-wish.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

apps/docs/lib/source.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { openapiPlugin } from 'fumadocs-openapi/server';
88
import { blog as blogPosts, docs } from '@/.source';
99
import { lucideIconsPlugin } from 'fumadocs-core/source/lucide-icons';
1010
import { openapi } from '@/lib/openapi';
11+
import { APIPage } from 'fumadocs-openapi/ui';
1112

1213
export const source = loader(docs.toFumadocsSource(), {
1314
baseUrl: '/docs',
1415
plugins: [
1516
lucideIconsPlugin(),
1617
await openapiPlugin.withPages({
1718
from: openapi,
19+
APIPage,
1820
baseDir: 'openapi/(generated)',
1921
}),
2022
],

packages/openapi/src/server/source-api.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import type {
88
} from 'fumadocs-core/source';
99
import type { OpenAPIServer } from '@/server/create';
1010
import type { SchemaToPagesOptions } from '@/utils/schema-to-pages';
11+
import type { FC } from 'react';
12+
import type { ApiPageProps } from '@/render/api-page';
1113

1214
export type WithPagesOptions = SchemaToPagesOptions & {
1315
from: OpenAPIServer;
16+
APIPage: FC<ApiPageProps>;
1417
baseDir?: string;
1518
};
1619

@@ -65,14 +68,15 @@ export function openapiPlugin(): LoaderPlugin {
6568
/**
6669
* Generate virtual pages
6770
*/
68-
openapiPlugin.withPages = async (
69-
options: WithPagesOptions,
70-
): Promise<LoaderPlugin> => {
71-
const { from, baseDir = '' } = options;
72-
71+
openapiPlugin.withPages = async ({
72+
from,
73+
baseDir = '',
74+
APIPage,
75+
...base
76+
}: WithPagesOptions): Promise<LoaderPlugin> => {
7377
const { serverToPages } = await import('@/utils/schema-to-pages');
7478
const { toBody } = await import('@/utils/pages/to-body');
75-
const entries = await serverToPages(from, options);
79+
const entries = await serverToPages(from, base);
7680
const plugin = openapiPlugin();
7781
let loaderConfig: ResolvedLoaderConfig;
7882
plugin.config = (loaded) => {
@@ -102,7 +106,7 @@ openapiPlugin.withPages = async (
102106
: undefined,
103107
},
104108
},
105-
body: toBody(from, page),
109+
body: toBody(from, APIPage, page),
106110
}),
107111
path: page.path,
108112
absolutePath: '',

packages/openapi/src/utils/pages/to-body.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
import type { OutputEntry } from '@/utils/schema-to-pages';
2-
import { FC, lazy } from 'react';
2+
import type { FC } from 'react';
33
import type { ApiPageProps } from '@/render/api-page';
44
import type { OpenAPIServer } from '@/server';
55

6-
const APIPageDefault = lazy(() =>
7-
import('@/ui').then((mod) => ({
8-
default: mod.APIPage,
9-
})),
10-
);
11-
12-
export function toBody(server: OpenAPIServer, entry: OutputEntry): FC<unknown> {
13-
const APIPage = (props: ApiPageProps) => (
14-
<APIPageDefault {...server.getAPIPageProps(props)} />
15-
);
16-
6+
export function toBody(
7+
server: OpenAPIServer,
8+
APIPage: FC<ApiPageProps>,
9+
entry: OutputEntry,
10+
): FC<unknown> {
1711
return function body() {
1812
if (entry.type === 'operation')
1913
return (
2014
<APIPage
21-
hasHead={false}
22-
document={entry.schemaId}
23-
operations={[entry.item]}
15+
{...server.getAPIPageProps({
16+
hasHead: false,
17+
document: entry.schemaId,
18+
operations: [entry.item],
19+
})}
2420
/>
2521
);
2622
if (entry.type === 'webhook')
2723
return (
2824
<APIPage
29-
hasHead={false}
30-
document={entry.schemaId}
31-
webhooks={[entry.item]}
25+
{...server.getAPIPageProps({
26+
hasHead: false,
27+
document: entry.schemaId,
28+
webhooks: [entry.item],
29+
})}
3230
/>
3331
);
3432

3533
return (
3634
<APIPage
37-
hasHead
38-
document={entry.schemaId}
39-
operations={entry.operations}
40-
webhooks={entry.webhooks}
35+
{...server.getAPIPageProps({
36+
hasHead: true,
37+
document: entry.schemaId,
38+
operations: entry.operations,
39+
webhooks: entry.webhooks,
40+
})}
4141
/>
4242
);
4343
};

0 commit comments

Comments
 (0)