OpenApiTsGen 0.1.2
dotnet add package OpenApiTsGen --version 0.1.2
NuGet\Install-Package OpenApiTsGen -Version 0.1.2
<PackageReference Include="OpenApiTsGen" Version="0.1.2" />
<PackageVersion Include="OpenApiTsGen" Version="0.1.2" />
<PackageReference Include="OpenApiTsGen" />
paket add OpenApiTsGen --version 0.1.2
#r "nuget: OpenApiTsGen, 0.1.2"
#:package OpenApiTsGen@0.1.2
#addin nuget:?package=OpenApiTsGen&version=0.1.2
#tool nuget:?package=OpenApiTsGen&version=0.1.2
OpenApiTsGen
OpenApiTsGen reads an OpenAPI JSON document exposed by an ASP.NET Core application and writes a typed TypeScript client (apiserver.ts) plus model declarations (models.ts). It preserves required/optional and nullable schema metadata, path/query/header parameters, JSON bodies, multipart forms, and binary uploads.
Install
dotnet add package OpenApiTsGen
The package targets .NET 8 and can be consumed by ASP.NET Core 8 or newer applications.
Configure ASP.NET Core
First expose an OpenAPI document (Swagger is used here only as an example):
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddTsApiGen(builder.Configuration);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.TsApiGen();
}
Add the following configuration to appsettings.Development.json:
{
"TsApiGen": {
"OpenApiUrl": "/swagger/v1/swagger.json",
"OutputDir": "ClientApp/src/api",
"Route": "/tools/ts-api-gen",
"ApiFileName": "apiserver.ts",
"ModelsFileName": "models.ts"
}
}
Run the API and call GET /tools/ts-api-gen. Relative output paths are resolved from the ASP.NET Core content root. Relative OpenAPI URLs are resolved on the same host as the generation request. When calling OpenApiTypeScriptApiGenerator.GenerateAsync() directly (for example from a build tool), configure an absolute OpenApiUrl.
You may configure the generator without an IConfiguration section:
builder.Services.AddTsApiGen(options =>
{
options.OpenApiUrl = "https://localhost:7001/swagger/v1/swagger.json";
options.OutputDir = "ClientApp/src/api";
});
Keep the generation endpoint development-only or protect it with authorization: it makes an HTTP request and writes files on the server. Do not expose it publicly in production.
OpenAPI contract guidelines
The input must be an OpenAPI 3.x JSON document. For stable and useful generated contracts:
- Give every operation a unique, stable
operationId; it becomes the TypeScript method name. Without one, the name is derived from the HTTP method and route. - Put reusable DTOs under
components.schemasand use$ref. Mark non-optional properties in the schema'srequiredarray and express nullability explicitly (nullable: truein OpenAPI 3.0, or a null union in OpenAPI 3.1). - Declare contract-critical headers as explicit header parameters. Do not rely on prose descriptions for required inputs.
- Keep route groups and tags consistent, and use distinct
operationIdvalues across the entire API. - Describe path, query, and header parameters with their correct
inandrequiredvalues. OpenAPI requires path parameters to be required. - Use
application/jsonfor JSON request bodies andmultipart/form-datawithtype: string,format: binaryfor file fields. - Avoid renaming schemas, properties, routes, or
operationIdvalues after publishing a client; those are client contract changes.
Complete integration guides with stable operation names, nullable fields, JSON bodies, and file upload metadata are available for both application styles:
Generated client usage
The generated API module uses Axios. Install it in the consuming frontend:
npm install axios
Pass contract headers through the generated method argument when the OpenAPI document declares them as parameters. Cross-cutting headers such as authorization can also be supplied through the generated request config.
Generated files should normally be regenerated from a committed OpenAPI contract and reviewed like source changes. In CI, compare regenerated output with the committed files to detect server/client drift.
License
OpenApiTsGen is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.2 | 95 | 8/26/2026 |