@@ -3,8 +3,12 @@ title: OpenAPI
33description : Generating docs for OpenAPI schema
44---
55
6- <Callout type = " warning" title = " Server Component Only" >
7- It only works under RSC environments.
6+ <Callout type = " warning" title = " Before Reading" >
7+
8+ - Only OpenAPI 3.0 and 3.1 are supported.
9+ - It only works under RSC
10+ environments.
11+
812</Callout >
913
1014## Manual Setup
@@ -32,7 +36,7 @@ Add the following line:
3236@import ' fumadocs-openapi/css/preset.css' ;
3337```
3438
35- ### Configure Pages
39+ ### Configure Plugin
3640
3741Create an OpenAPI instance on the server.
3842
@@ -76,6 +80,34 @@ export default defineClientConfig({
7680});
7781```
7882
83+ ### Generate Pages
84+
85+ <Tabs items = { [" MDX Files" , " Virtual Files" ]} >
86+ <Tab >
87+
88+ You can generate MDX files directly from your OpenAPI schema.
89+
90+ Create a script:
91+
92+ ``` js title="scripts/generate-docs.ts"
93+ import { generateFiles } from ' fumadocs-openapi' ;
94+ import { openapi } from ' @/lib/openapi' ;
95+
96+ void generateFiles ({
97+ input: openapi,
98+ output: ' ./content/docs' ,
99+ // we recommend to enable it
100+ // make sure your endpoint description doesn't break MDX syntax.
101+ includeDescription: true ,
102+ });
103+ ```
104+
105+ Generate docs with the script:
106+
107+ ``` bash
108+ bun ./scripts/generate-docs.ts
109+ ```
110+
79111Add the ` APIPage ` component to your MDX Components.
80112
81113``` tsx title="mdx-components.tsx"
@@ -93,33 +125,60 @@ export function getMDXComponents(components?: MDXComponents): MDXComponents {
93125}
94126```
95127
96- ### Generate Files
128+ </Tab >
129+ <Tab >
97130
98- You can generate MDX files directly from your OpenAPI schema.
99-
100- Create a script:
131+ You can also use it without generating real files by integrating into [ Loader API] ( /docs/headless/source-api/source ) .
101132
102- ``` js title="scripts/generate-docs.ts"
103- import { generateFiles } from ' fumadocs-openapi' ;
133+ ``` ts title="lib/source.ts"
134+ import { loader , multiple } from ' fumadocs-core/source' ;
135+ import { openapiPlugin , openapiSource } from ' fumadocs-openapi/server' ;
136+ import { docs } from ' fumadocs-mdx:collections/server' ;
104137import { openapi } from ' @/lib/openapi' ;
105138
106- void generateFiles ({
107- input: openapi,
108- output: ' ./content/docs' ,
109- // we recommend to enable it
110- // make sure your endpoint description doesn't break MDX syntax.
111- includeDescription: true ,
112- });
139+ export const source = loader (
140+ // [!code ++:6]
141+ multiple ({
142+ docs: docs .toFumadocsSource (),
143+ openapi: await openapiSource (openapi , {
144+ baseDir: ' openapi' ,
145+ }),
146+ }),
147+ {
148+ baseUrl: ' /docs' ,
149+ plugins: [openapiPlugin ()],
150+ // ...
151+ },
152+ );
113153```
114154
115- > Only OpenAPI 3.0 and 3.1 are supported .
155+ It shares a different type from your original source, explicit handling of OpenAPI pages might be necessary (e.g. in your page component) .
116156
117- Generate docs with the script:
157+ ``` tsx title="docs/[[...slug]]/page.tsx"
158+ import { APIPage } from ' @/components/api-page' ;
118159
119- ``` bash
120- bun ./scripts/generate-docs.ts
160+ function Page() {
161+ const page = source .getPage (' ...' );
162+
163+ if (page .data .type === ' openapi' ) {
164+ return (
165+ <DocsPage full >
166+ <h1 className = " text-[1.75em] font-semibold" >{ page .data .title } </h1 >
167+
168+ <DocsBody >
169+ <APIPage { ... page .data .getAPIPageProps ()} />
170+ </DocsBody >
171+ </DocsPage >
172+ );
173+ }
174+
175+ // your original flow below...
176+ }
121177```
122178
179+ </Tab >
180+ </Tabs >
181+
123182## Features
124183
125184The official OpenAPI integration supports:
0 commit comments