OpenAPI
Build API documentations with Fumapress.
Installation
npm i fumadocs-openapi shikiConfigure the plugin:
import { defineConfig } from "fumapress";
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({
content: {
docs: docs.toFumadocsSource(),
openapi: await openapi.staticSource(),
},
})
// fumapress plugin
.plugins(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 { docs } from "./.source/server";
export default defineConfig({
content: {
docs: docs.toFumadocsSource(),
openapi: await openapi.staticSource({
baseDir: "(openapi)",
}),
},
});Client UI
Create the renderer for API pages explicitly:
"use client";
import { createOpenAPIPage } from "fumadocs-openapi/ui";
export const OpenAPIPage = createClientAPIPage();And import it from the OpenAPI plugin:
import { OpenAPIPage } from "./src/components/openapi";
export default defineConfig({
// ...
}).plugins(
openapiPlugin({
server: openapi,
ClientAPIPage: OpenAPIPage,
}),
);Proxy Server
To create the Proxy Server, define proxyUrl in createOpenAPI() 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({
// ...
}).plugins(
openapiPlugin({
server: openapi,
}),
);Last updated on
