OpenAPI
Build API documentations with Fumapress.
Installation
npm i fumadocs-openapi shikiConfigure the plugin:
import { defineConfig } from "fumapress";
import { loader } from "fumadocs-core/source";
import { docs } from "./.source/server";
import path from "node:path";
import { createOpenAPI } from "fumadocs-openapi/server";
import { openapiPlugin } from "fumapress/plugins/openapi";
const openapi = createOpenAPI({
// path or URL to your OpenAPI spec
input: [path.resolve("./openapi.json")],
});
export default defineConfig({
loader: loader(
{
docs: docs.toFumadocsSource(),
openapi: await openapi.staticSource(),
},
{
baseUrl: "/",
// loader plugin
plugins: [openapi.loaderPlugin()],
},
),
})
// fumapress plugin
.usePlugins(openapiPlugin({ server: openapi }));Update the path/URL to your OpenAPI spec (e.g. ./openapi.json), the API pages will be automatically generated based on your spec.
Options
You can see Fumadocs OpenAPI for details of advanced options.
openapi.staticSource()
It support a subset of options from generateFiles().
How to customize its output file structure?
It accepts a baseDir option. For example, the following will generate all API pages under the (openapi) folder:
import { defineConfig } from "fumapress";
import { loader } from "fumadocs-core/source";
import { docs } from "./.source/server";
export default defineConfig({
loader: loader(
{
docs: docs.toFumadocsSource(),
openapi: await openapi.staticSource({
baseDir: "(openapi)",
}),
},
// ...
),
});Client UI
Create the renderer for API pages explicitly:
"use client";
import { createClientAPIPage } from "fumadocs-openapi/ui/create-client";
export const ClientAPIPage = createClientAPIPage();And import it from the OpenAPI plugin:
import { ClientAPIPage } from "./src/components/api";
export default defineConfig({
// ...
}).usePlugins(
openapiPlugin({
server: openapi,
ClientAPIPage,
}),
);Proxy Server
To create the Proxy Server, update your server & plugin options:
import { defineConfig } from "fumapress";
import { createOpenAPI } from "fumadocs-openapi/server";
import { openapiPlugin } from "fumapress/plugins/openapi";
const openapi = createOpenAPI({
proxyUrl: "/_proxy",
});
export default defineConfig({
// ...
}).usePlugins(
openapiPlugin({
server: openapi,
createProxy: true,
}),
);Last updated on
