QUESTPIE
Production

OpenAPI

Auto-generate OpenAPI 3.1 spec and interactive API docs from your schema.

QUESTPIE auto-generates an OpenAPI 3.1 spec from your collections, globals, and routes at runtime. The spec is served as a standard route alongside interactive Scalar API docs.

Setup

Install the OpenAPI package:

bun add @questpie/openapi

Register the module in your modules.ts:

questpie/server/modules.ts
import { adminModule } from "@questpie/admin/server";
import { openApiModule } from "@questpie/openapi";

export default [
	adminModule,
	openApiModule({
		info: {
			title: "My API",
			version: "1.0.0",
		},
	}),
] as const;

Run codegen to pick up the new module:

bunx questpie generate

The module registers two routes:

RouteDescription
GET /api/openapi.jsonOpenAPI 3.1 JSON spec
GET /api/docsScalar interactive API reference

Configuration

openApiModule({
	// OpenAPI info block
	info: {
		title: "My API",
		version: "1.0.0",
		description: "Backend for my app",
	},

	// Server definitions
	servers: [{ url: "https://api.example.com", description: "Production" }],

	// Base path (must match your adapter's basePath)
	basePath: "/api",

	// Exclude specific collections or globals from the spec
	exclude: {
		collections: ["_internal_logs"],
		globals: ["_cache"],
	},

	// Include auth endpoints (sign-in, sign-up, etc.)
	auth: true,

	// Include search endpoints
	search: true,

	// Scalar UI theme
	scalar: {
		theme: "purple",
	},

	// Custom route keys (defaults shown)
	specPath: "openapi.json",
	docsPath: "docs",
});

What Gets Documented

The spec is generated at runtime from your app's schema:

SourceDocumented As
CollectionsCRUD endpoints (GET /collections/{name}, POST, PUT, DELETE)
GlobalsRead/update endpoints (GET /globals/{name}, PUT)
RoutesApp routes (/api/{path}) with input/output schemas when available
AuthSign-in, sign-up, session endpoints (when auth: true)
SearchSearch endpoints (when search: true)

Collection and global field schemas (from Zod) are automatically converted to JSON Schema in the spec. Route input/output schemas are included when defined.

Manual Route Approach

Instead of the module, you can create route files directly:

routes/openapi.json.ts
import { openApiRoute } from "@questpie/openapi";

export default openApiRoute({
	info: { title: "My API", version: "1.0.0" },
});
routes/docs.ts
import { docsRoute } from "@questpie/openapi";

export default docsRoute({
	scalar: { theme: "purple" },
});

This gives you full control over the route paths and allows co-locating OpenAPI config with other route files.

Programmatic Access

Generate the spec object directly for custom use cases:

import { generateOpenApiSpec } from "@questpie/openapi";

const spec = generateOpenApiSpec(app, {
	info: { title: "My API", version: "1.0.0" },
});

// Use spec object for testing, CI validation, etc.

On this page