Fumadocs

createOpenAPI()

The OpenAPI server instance.

OpenAPI Server

The main config for Fumadocs OpenAPI.

It should not be referenced in browser environments.

input

The OpenAPI schemas to read from.

  • File Paths
  • External URLs
  • A function (see below)
import { createOpenAPI } from 'fumadocs-openapi/server';

export const openapi = createOpenAPI({
  input: ['./unkey.json'],
});

Creating Proxy

A proxy server is useful for executing HTTP (fetch) requests, as it doesn't have CORS constraints like on the browser. We can use it for executing HTTP requests on the OpenAPI playground, when the target API endpoints do not have CORS configured correctly.

Warning

Do not use this on unreliable sites and API endpoints, the proxy server will forward all received headers & body, including HTTP-only Cookies and Authorization header.

Setup

Create a route handler for proxy server.

/api/proxy/route.ts
import { openapi } from '@/lib/openapi';

export const { GET, HEAD, PUT, POST, PATCH, DELETE } = openapi.createProxy({
  // optional, we recommend to set a list of allowed origins for proxied requests
  allowedOrigins: ['https://example.com'],
});

Follow the Getting Started guide if openapi instance is not yet configured.

And set the proxy URL in createOpenAPI.

lib/openapi.ts
import { createOpenAPI } from 'fumadocs-openapi/server';

export const openapi = createOpenAPI({
  proxyUrl: '/api/proxy',
});

How is this guide?

Last updated on