@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-forgenpx @mrzr/openapi-forge --input swagger.json --out src/api/generatednpx @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 staleimport { useListPetsQuery, useCreatePetMutation } from "./api/generated";
const pets = useListPetsQuery({ kind: "cat" });
const create = useCreatePetMutation();
create.mutate({ body: { name: "Tom" } });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.
Guides
More in api layer