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.
In code
Section titled “In code”import { toOpenApi } from "@mountsqli/api";
const spec = toOpenApi(router, "My API");// → OpenAPI 3.1 object keyed by routeWith the CLI
Section titled “With the CLI”mountsqli api generateIt reads the output path from mountsqli.config.js or defaults to
openapi.json. The dev server also serves the spec for Studio.
What’s in the spec
Section titled “What’s in the spec”- 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.
Real-world example
Section titled “Real-world example”const router = createRouter();router.get("/users", { plan: db.from(users)._plan, description: "List users" });const spec = toOpenApi(router, "Users API");Best practices
Section titled “Best practices”- Name every route — the name is the operationId consumers see.
- Add a
descriptionper route for better docs. - Regenerate the spec in CI so it never drifts from code.
Common mistakes
Section titled “Common mistakes”- Forgetting route names — OpenAPI operationIds become generic.
- Hand-writing the spec instead of generating from the router.
Related
Section titled “Related”- REST Handler — serve the router.
- RPC — the tRPC-style alternative.
