Getting started
Install
npm i -D geneverpnpm add -D geneveryarn add -D geneverTIP
genever requires Node.js 24 or later. Its output is plain TypeScript, so it is a dev dependency only.
Generate types
npx genever schemas/user.json --name Usergenever writes schemas/user.ts next to the schema (or -o to choose the path), and prints the file it wrote:
- The root schema becomes the type named by
--name(Schemaby default). - Every definition in the root
$defs(or draft 7definitions) becomes an exported type named after its key, in PascalCase, whether or not it is referenced. - A schema referenced by
$reffrom anywhere else in the document becomes a named type too, named after its key in any nested$defs, or else after its path. Everything else is inlined.
// Generated by genever. Do not edit by hand, regenerate it instead.
export type User = {
id: `usr_${string}`;
home?: Address;
};
export type Address = {
city: string;
};The file is formatted with your project's Biome or Prettier config, if either is installed.
If the schema has a mistake, such as a misspelled keyword, genever fails with a JSON Pointer to it instead of writing a looser type. See Strict mode.
Check types in CI
Commit the generated file, and check it is up to date in CI:
npx genever schemas/user.json --name User --ci--ci generates the types without writing, and fails if the file would change. It is on by default when genever detects CI (with ci-info), so the same command writes locally and checks in CI.
In an Nx workspace, a cached target per schema does that before compiling:
// project.json
{
"targets": {
"genever": {
"executor": "nx:run-commands",
"options": {
"command": "genever schemas/user.json --name User",
"cwd": "{projectRoot}"
},
"cache": true,
"inputs": ["{projectRoot}/schemas/user.json"],
"outputs": ["{projectRoot}/schemas/user.ts"]
}
}
}Next steps
- Type mapping: how each keyword becomes a type.
- Strict mode: the mistakes genever rejects, and what it generates without strict mode.
- OpenAPI documents: types for every schema of a spec.
- Juniper round trip: getting Juniper's types back from its JSON.
- API and CLI reference: every option, and running genever from code.