Skip to content

Getting started ​

Install ​

sh
npm i -D genever
sh
pnpm add -D genever
sh
yarn add -D genever

TIP

genever requires Node.js 24 or later. Its output is plain TypeScript, so it is a dev dependency only.

Generate types ​

sh
npx genever schemas/user.json --name User

genever 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 (Schema by default).
  • Every definition in the root $defs (or draft 7 definitions) becomes an exported type named after its key, in PascalCase, whether or not it is referenced.
  • A schema referenced by $ref from 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.
ts
// 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:

sh
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:

json
// 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 ​