Skip to content

What is generated

src/api/generated/
├── models.ts every schema as a type
├── pets.ts one module per tag: endpoints, keys, types, request functions, hooks
├── owners.ts
├── schemas.ts Zod validators (zod: true)
├── services.ts API_SERVICE_BASE_URLS (per-service base URLs)
├── index.ts re-exports everything
├── client.ts ┐ the built-in runtime, written once, yours to edit
├── hooks.ts │ (client.ts only for api-client and axios;
└── types.ts ┘ fetch and Angular's HttpClient need none)

A module (trimmed) looks like this:

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,
listPets: (params: ListPetsQuery) => [...petsKeys.lists(), petsEndpoints.listPets, params] as const,
getPet: (petId: string) => [...petsKeys.details(), petsEndpoints.getPet, petId] as const,
} as const;
export type ListPetsQuery = { start?: number; kind?: "cat" | "dog"; ids?: string[] };
/** List the pets — `GET /pets` */
export function listPets(config?: RequestConfig<ApiListData<Pet>>) { … } // api-client: the query is `params` in its own config
listPets({ params: { kind: "cat" } });
getPet({ addTemplateToUrl: { pet_id: "7" } }); // the path values are in the config too; getPet() does not compile
export function useListPetsQuery(params: ListPetsQuery = {}, options?: ApiQueryOptions<…>) { … }
export function useGetPetQuery(petId: string | undefined, options?: ApiQueryOptions<…>) { … }
export function useCreatePetMutation(options?: ApiMutationOptions<Pet, CreatePetVariables>) { … }
  • A write takes one variables object ({ petId, params, headers, body } — only the parts it has), named <Operation>Variables.
  • Query and header parameters get <Operation>Query / <Operation>Headers types. The query is called params, as every built-in client calls it (runtime.requestKeys.query names it for a custom transport). With @mrzr/api-client a request function takes only its body and the client’s own config: the query is params and the path values are addTemplateToUrl in that config (listPets({ params: { kind: "cat" } }), getPet({ addTemplateToUrl: { pet_id: "7" } })), and it goes to the client as it is. axios does the same for the query. The hooks keep everything typed (useListPetsQuery({ kind: "cat" }), useGetPetQuery("7")). fetch and Angular’s service take the path values and params as arguments, since neither has a config to carry them; path arguments keep the document’s names.
  • An operation with no tag goes to the default module.