Generate typed TypeScript clients from OpenAPI JSON

OpenApiGen is a .NET tool that turns your API definition into functions you can call with fetch or Axios.

OpenAPI operation GET /greetings/{name}
client.ts
import { getGreetingsName } from "./generated";

const [status, body] = await getGreetingsName(
  fetch,
  "Ada",
);

if (status === 200) {
  console.log(body.message);
}

Generate your first client

Start with an OpenAPI JSON file from your API and run the tool with the .NET 10 or .NET 11 SDK. OpenApiGen is tested with documents from ASP.NET Core 10 and 11. Documents from other tools can work when they use supported OpenAPI features.

See the ASP.NET Core example
Terminal
dotnet tool install --global MagnusOpera.OpenApiGen
openapigen --transport fetch openapi.json ./generated

One function per operation

Generated modules group operations by tag and export the request and response types alongside each function.

Typed status and body

Check the returned HTTP status to narrow the response type before reading the body.

Bring your HTTP client

Pass a fetch implementation or a configured Axios instance to control how requests reach your API.