# Fumadocs (Framework Mode, Next.js): OpenAPI
URL: /docs/next/integrations/openapi
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/openapi/index.mdx

Generating docs for OpenAPI schema.

## Setup [#setup]

Install the required packages.

```npm
npm i fumadocs-openapi shiki
```

### Generate Styles [#generate-styles]

Add the following line:

```css title="Tailwind CSS"
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';
/* [!code ++] */
@import 'fumadocs-openapi/css/preset.css';
```

### Configure Plugin [#configure-plugin]

Create the OpenAPI server instance and the `<OpenAPIPage />` component.

```ts tab="lib/openapi.ts"
import { createOpenAPI } from 'fumadocs-openapi/server';

// note: this is a server-side API
export const openapi = createOpenAPI({
  // the OpenAPI schema, you can also give it an external URL.
  input: ['./openapi.json'],
});
```

```tsx tab="components/api-page.tsx"
'use client';
import { createOpenAPIPage } from 'fumadocs-openapi/ui';

export const OpenAPIPage = createOpenAPIPage();
```

See [`createOpenAPI()`](/docs/next/integrations/openapi/server) and [`createOpenAPIPage()`](/docs/next/integrations/openapi/api-page) for their options.

### Generate Pages [#generate-pages]

Pass `staticSource()` to your [`loader()`](/docs/headless/source-api/source). It generates pages without writing files.

```ts title="lib/source.ts"
import { loader } from 'fumadocs-core/source';
import { defineDocs } from 'fumadocs-mdx/macro';
import { openapi } from '@/lib/openapi'; // [!code ++]

const docs = defineDocs({
  dir: 'content/docs',
});

export const source = loader(
  // [!code ++:6]
  {
    docs: docs.toFumadocsSource(),
    openapi: await openapi.staticSource({
      baseDir: 'openapi',
    }),
  },
  {
    baseUrl: '/docs',
    // [!code ++:2] optional: adds a badge to each page item in page tree
    plugins: [openapi.loaderPlugin()],
  },
);
```

`staticSource()` generates a page per operation by default. See [Generating Pages](/docs/next/integrations/openapi/generate-files) to customize them.

**Pages of `source` now have two types, `docs` and `openapi`.** Update every place that uses `source`, like where you return text for LLMs:

```ts
import { llms } from 'fumadocs-core/source';
import { source } from '@/lib/source';

export const docsLlms = llms(source, {
  renderPage: (page) => {
    // [!code ++:4]
    if (page.type === 'openapi') {
      // e.g. return the stringified OpenAPI schema
      return JSON.stringify(page.data.getSchema().bundled, null, 2);
    }

    // your original flow below...
  },
});
```

Render OpenAPI pages with `<OpenAPIPage />` in your docs page:

```tsx title="app/docs/[[...slug]]/page.tsx"
import { OpenAPIPage } from '@/components/api-page'; // [!code ++]

export default async function Page(props: PageProps<'/docs/[[...slug]]'>) {
  const params = await props.params;
  const page = source.getPage(params.slug);
  if (!page) notFound();

  // [!code ++:10]
  if (page.type === 'openapi') {
    return (
      <DocsPage full>
        <DocsTitle>{page.data.title}</DocsTitle>
        <DocsBody>
          <OpenAPIPage {...page.data.getOpenAPIPageProps()} />
        </DocsBody>
      </DocsPage>
    );
  }

  // ...
}
```

<Callout type="warn" title="Ensure the migration is complete!">
Run a type check before continuing:

```npm
npm run types:check
```
</Callout>

To write MDX files into your content directory instead, see [MDX Files](/docs/next/integrations/openapi/generate-files#mdx-files).

## Features [#features]

The official OpenAPI integration supports:

- Basic API endpoint information
- Interactive API playground
- Example code to send request (in different programming languages)
- Response samples and TypeScript definitions
- Request parameters and body generated from schemas

### Demo [#demo]

[View demo](/docs/openapi).