PeaBox Lab › PeaLang › Learn › Chapter 28 › Lesson 3

Part V — The Modern Experience Layer · Chapter 28 · Lesson 3 of 3

OpenAPI 3.0 generation and typed SDKs

The last serious ergonomic gap in hand-rolled APIs is the spec drifting away from the routes. PeaLang closes it: the spec is generated from the app object you already have.

Generate the spec

let spec = web.openapi(app, {
  "title": "Orders API",
  "version": "1.2.0",
  "description": "Internal order service"
})

web.openapi walks the registered routes — paths, methods, path parameters, response helpers with known codes — and emits an OpenAPI 3.0 document. Path params in :id form become OpenAPI {id} form automatically; route groups appear as path prefixes; static and 404 routes are excluded.

Serve it

app.get("/openapi.json", fn(req) {
  return web.json(spec)
})

Or use the CLI: pea openapi (and its alias web-openapi) generate the document from a source file without running the service — ideal for CI.

From spec to typed clients

The code generators read the same route table or the emitted spec:

Versioning without pain

app.group("/v1")  →  /v1/orders
app.group("/v2")  →  /v2/orders

api_versioning_source generates the router sketch for header- or path-based versioning. Pick path-based; header-based versioning is a liability in cached proxies and support tickets alike.

Guided practice

Rule of thumb. If your spec is written by hand, it is already wrong. Generate it, diff it in CI, and treat it as a build artifact.

← Previous Next →