Skip to content

OpenAPI & Codegen

Your Router is the single source for an OpenAPI document. toOpenApi(router) produces OpenAPI 3.1 JSON; the CLI writes it to disk.

import { toOpenApi } from "@mountsqli/api";
const spec = toOpenApi(router, "My API");
// → OpenAPI 3.1 object keyed by route
Terminal window
mountsqli api generate

It reads the output path from mountsqli.config.js or defaults to openapi.json. The dev server also serves the spec for Studio.

  • Each named route becomes an OpenAPI operation (operationId = route name).
  • CRUD routes expand to list/create/read/update/delete operations.
  • Validation shapes (ValidationShape) become request/response schemas.
const router = createRouter();
router.get("/users", { plan: db.from(users)._plan, description: "List users" });
const spec = toOpenApi(router, "Users API");
  • Name every route — the name is the operationId consumers see.
  • Add a description per route for better docs.
  • Regenerate the spec in CI so it never drifts from code.
  • Forgetting route names — OpenAPI operationIds become generic.
  • Hand-writing the spec instead of generating from the router.