MagnusOpera.OpenApiGen
0.47.0
Prefix Reserved
dotnet tool install --global MagnusOpera.OpenApiGen --version 0.47.0
dotnet new tool-manifest
dotnet tool install --local MagnusOpera.OpenApiGen --version 0.47.0
#tool dotnet:?package=MagnusOpera.OpenApiGen&version=0.47.0
nuke :add-package MagnusOpera.OpenApiGen --version 0.47.0
OpenApiGen
OpenApiGen is a .NET tool that generates simple, type-safe TypeScript clients from OpenAPI definitions. The generated clients are designed for easy integration with Axios or fetch.
The package includes .NET 10 and .NET 11 targets. It accepts OpenAPI 3.0, 3.1, and 3.2 JSON for supported HTTP operations and payloads, including OpenAPI 3.2 QUERY.
Usage
Run the tool with:
openapigen --transport <axios|fetch> <openapi-file> <output-dir>
--transport <axios|fetch>: Mandatory transport to generate<openapi-file>: Path to the OpenAPI definition JSON file<output-dir>: Output directory for the generated TypeScript client (will be purged)
For help:
openapigen --help
Note on Any Types
This tool implements a workaround for a bug in Microsoft.Extensions.ApiDescription.Server 9.0.8, where nullable types are incorrectly emitted as type "any" in the OpenAPI definition. The generator heuristically locates an equivalent non-nullable schema and applies the intended nullability. This assumes the base, non-nullable schema is emitted correctly.
Example Output
Sample TypeScript code generated for a PATCH operation on /User/{id} using the Axios transport:
// === patch /User/{id} ===
export type UserIdPatchRequest = {
firstName: null | string
lastName: null | string
}
export type UserIdPatch200Response = {
firstName: string
lastName: string
}
export type UserIdPatch400Response = ProblemDetails
export type UserIdPatch404Response = ProblemDetails
export async function patchUserId(axios: AxiosInstance, bearer: string, id: string, request: UserIdPatchRequest): Promise<[200, UserIdPatch200Response] | [400, UserIdPatch400Response] | [404, UserIdPatch404Response]> {
const __queryString__ = "";
const __headers__: Record<string, string> = {};
__headers__.Authorization = `Bearer ${bearer}`;
__headers__["Content-Type"] = "application/json";
const __response__ = await axios.request({
method: "PATCH",
url: `/User/${id}${__queryString__}`,
data: JSON.stringify(request),
headers: __headers__,
validateStatus: () => true,
});
switch (__response__.status) {
case 200: return [200, __response__.data as UserIdPatch200Response]
case 400: return [400, __response__.data as UserIdPatch400Response]
case 404: return [404, __response__.data as UserIdPatch404Response]
default: throw Error(`Unexpected status ${__response__.status}`)
}
}
Features
- Generates TypeScript clients from OpenAPI definitions
- Supports Axios and fetch transports
- Inlines types for clarity and simplicity
- Support for Bearer token (authorization header) and ApiKey (cookie)
- Minimal dependencies, no runtime bloat
Note on Nullable Types
This tool implements a workaround for a bug in Microsoft.Extensions.ApiDescription.Server 9.0.8, where nullable types are incorrectly emitted as type "any" in the OpenAPI definition. The generator heuristically locates an equivalent non-nullable schema (with the same required members) and applies the intended nullability. This assumes the base, non-nullable schema is emitted correctly.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
This package has no dependencies.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 0.47.0 | 163 | 11/14/2026 | |
| 0.46.0 | 2,542 | 4/8/2026 | |
| 0.45.0 | 171 | 4/1/2026 | |
| 0.44.0 | 153 | 4/1/2026 | |
| 0.43.0 | 1,699 | 11/22/2025 | |
| 0.42.0 | 399 | 11/12/2025 | |
| 0.41.0 | 332 | 11/12/2025 | |
| 0.40.0 | 325 | 11/12/2025 | |
| 0.39.0 | 331 | 11/12/2025 | |
| 0.38.0 | 692 | 11/11/2025 | |
| 0.37.0 | 324 | 11/11/2025 | |
| 0.36.0 | 499 | 11/10/2025 | |
| 0.35.0 | 245 | 11/3/2025 | |
| 0.34.0 | 360 | 10/27/2025 | |
| 0.33.2 | 171 | 10/18/2025 | |
| 0.33.1 | 184 | 10/18/2025 | |
| 0.33.0 | 606 | 9/23/2025 | |
| 0.32.0 | 285 | 9/13/2025 | |
| 0.31.0 | 165 | 9/13/2025 | |
| 0.30.0 | 247 | 9/7/2025 |