@mrzr/openapi-forge

A typed API layer, generated from your OpenAPI documents.

Models, request functions, query keys and data-fetching hooks for React, Vue, Svelte, Solid or Angular Query, or SWR. Plain, readable, deterministic TypeScript, so CI can fail when the committed layer is stale.

npm i -D @mrzr/openapi-forge
npx @mrzr/openapi-forge --input swagger.json --out src/api/generated
Version
v0.4.1
Published
Nov 2026
License
MIT
Requirements
Node.js 20 or newer. Swagger 2.0, OpenAPI 3.0 and 3.1, as JSON or YAML, from a file, a folder or a URL. One runtime dependency (yaml).
Generatebash
npx @mrzr/openapi-forge init        # writes openapi-forge.config.yaml
npx @mrzr/openapi-forge --input swagger.json --out src/api/generated --api-prefix /api/v1
npx @mrzr/openapi-forge --check     # exit 1 when the committed layer is stale
Usets
import { useListPetsQuery, useCreatePetMutation } from "./api/generated";

const pets = useListPetsQuery({ kind: "cat" });
const create = useCreatePetMutation();
create.mutate({ body: { name: "Tom" } });
What a module looks likets
export const petsEndpoints = {
  listPets: "/pets",
  getPet: "/pets/{pet_id}",
} as const;

export const petsKeys = {
  all: ["Pets"] as const,
  lists: () => [...petsKeys.all, "list"] as const,
  details: () => [...petsKeys.all, "detail"] as const,
  getPet: (petId: string) => [...petsKeys.details(), petsEndpoints.getPet, petId] as const,
} as const;

What it does

Models and routes

One type per schema, including allOf / oneOf, tuples, records and circular references. Every URL is written once, in <tag>Endpoints.

Query-key factories

all, lists(), details() and one key per read, so invalidating a tag, its lists or its details is one line.

Hooks for six libraries

React, Vue, Svelte, Solid and Angular Query, or SWR. Reactive arguments in Vue, Svelte, Solid and Angular.

Your HTTP client, called as itself

@mrzr/api-client, fetch, axios or Angular HttpClient, each with its own answer type, or your own transport.

Several services, one layer

Merge specs from many backends, with conflicts decided once and committed. Per-service base URLs.

Change reports

diff says what a new spec breaks in terms of your code, as breaking / risky / safe, with --fail-on for CI.

Documentation

Everything is documented.

Start reading

More in api layer