Skip to content

Quick start

Terminal window
npm i -D @mrzr/openapi-forge
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

With the default client: "builtin" small files are written once next to the layer (client.ts, hooks.ts and types.ts). They are yours to edit and are never overwritten (--force-runtime resets them). The hooks need the package of the library they wrap — @tanstack/react-query v5 by default, see Hook libraries.

// src/api/generated/client.ts — written once, yours to edit. The default client is @mrzr/api-client:
// it finds its base URL in the environment (VITE_API_URL, …); give it the tokens and plugins it needs.
export const apiClient = createClient();
import { useListPetsQuery, useCreatePetMutation } from "./api/generated";
const pets = useListPetsQuery({ kind: "cat" }); // pets.data is api-client's own answer: pets.data?.data is the list
const create = useCreatePetMutation();
create.mutate({ body: { name: "Tom" } });

Without @mrzr/api-client, pick another client with http: "axios", "fetch" (nothing to install; functions only, --target requests) or "angular" (an injectable service over HttpClient). Each is called as itself — see HTTP clients.