Scaffold from OpenAPI
routa scaffold reads an OpenAPI document and writes the source contract it describes:
one route file per path, a schema module beside it, and the .routa/ metadata that later
checks compare against. Run it when you have an agreed API contract and want the
TypeScript source to match it.
Before You Start
Section titled “Before You Start”- A Routa project. Scaffolding refuses to run outside one.
- An OpenAPI document with a
.yaml,.yml, or.jsonextension in the project. - No
OPTIONSoperations in the document. Routa generates those at runtime.
-
Preview the changes. Nothing is written in preview mode, so run this first every time.
Terminal window npx routa scaffold openapi.yaml --previewTerminal window pnpm exec routa scaffold openapi.yaml --previewTerminal window yarn exec routa scaffold openapi.yaml --previewTerminal window bunx routa scaffold openapi.yaml --preview -
Read the change list. Each generated path is marked with what would happen to it.
Marker Meaning + addNew file that does not exist yet ~ updateTracked generated file whose content would change = unchangedGenerated file already matches ! conflictA file exists at that path that Routa does not track - removePreviously generated file no longer described by the document -
Resolve every conflict before continuing. Move or rename any file marked
! conflictthat you want to keep, since Routa refuses to overwrite files it did not generate. -
Apply the changes.
Terminal window npx routa scaffold openapi.yaml --yesTerminal window pnpm exec routa scaffold openapi.yaml --yesTerminal window yarn exec routa scaffold openapi.yaml --yesTerminal window bunx routa scaffold openapi.yaml --yes -
Validate and typecheck the generated source.
Terminal window npm run checkTerminal window pnpm run checkTerminal window yarn run checkTerminal window bun run check
Verify
Section titled “Verify”Scaffolding reports what it wrote:
Scaffolded 4 Routa route file(s).src/routes/users/route.tssrc/routes/users/schemas.tssrc/routes/users/$userId/route.tssrc/routes/users/$userId/schemas.ts.routa/openapi-baseline.json.routa/manifest.json.routa/routes.gen.tsGenerated handlers are stubs. They satisfy the contract and return placeholder data, so
routa check passes immediately and you can fill in the service calls one route at a time.
What Gets Generated
Section titled “What Gets Generated”| From the document | Into source |
|---|---|
| Path and method | src/routes/**/route.ts with a createRoute per method |
| Parameters | input.params, input.query, input.headers, input.cookies |
| JSON request body | input.body |
| JSON responses | Entries in responses, named from status and operationId |
components.schemas |
Shared schema modules referenced by routes |
| The whole document | .routa/openapi-baseline.json |
Supported input is deliberately narrow: paths, methods, operationId, path/query/header/
cookie parameters, JSON bodies, JSON responses, and components.schemas. Anything else
stays in the source document and is not approximated in TypeScript.
Troubleshooting
Section titled “Troubleshooting”| Problem | Fix |
|---|---|
ROUTA_OPENAPI_UNSUPPORTED_EXTENSION |
Rename the document to .yaml, .yml, or .json. |
ROUTA_OPENAPI_FILE_NOT_FOUND |
Run from the project root, or pass the path relative to it. |
Regeneration requires preview or confirmation. |
A manifest already exists. Re-run with --preview, then with --yes. |
ROUTA_SCAFFOLD_UNMANAGED_FILE |
A file exists where Routa wants to generate one, and the manifest does not track it. Move or rename yours. |
ROUTA_SCAFFOLD_MODIFIED_GENERATED_FILE |
You edited a generated file. Move the edits into application-owned code, or accept losing them. |