MetaEngine.CSharp.OpenApi.HttpClient.Tool
OpenAPI 3.x → an idiomatic C# HttpClient API client and System.Text.Json models — the native .NET path. Smart HTTP-status error handling, bearer/basic auth, retries, custom headers, DataAnnotations validation and DI middleware. Ships as a NuGet library for programmatic/build-tool use plus a dotnet tool CLI.
Pick your registry
The same generator, published to every ecosystem we support. Install however your project expects.
Drive it from the CLI or programmatically
dotnet tool ships a zero-config CLI. NuGet ships the same generator as a C# fluent API — same options, same output.
After install, point the CLI at your schema. It writes the generated tree to your chosen output directory.
metaengine-openapi-csharp-httpclient <input> <output> <namespace> [options]Installed as a global dotnet tool: dotnet tool install --global MetaEngine.CSharp.OpenApi.HttpClient.Tool. Takes three positional arguments in order — <input> (OpenAPI spec file path or URL), <output> (directory for the generated C# files), and <namespace> (root namespace for the client and models). Accepts OpenAPI 3.0 and 3.1 in JSON or YAML.
dotnet tool install --global MetaEngine.CSharp.OpenApi.HttpClient.Toolmetaengine-openapi-csharp-httpclient openapi.yaml ./Generated MyApp.Apimetaengine-openapi-csharp-httpclient openapi.yaml ./Generated MyApp.Api \
--bearer-auth API_TOKEN \
--retries 3 \
--error-handling \
--documentationmetaengine-openapi-csharp-httpclient https://api.example.com/openapi.json ./Generated MyApp.Api \
--include-tags payments,refunds \
--middleware \
--custom-header X-Tenant-ID=TENANT_IDEvery knob, documented
Every option is available on the C# fluent API as a method, and most are also exposed as CLI flags. Cross-cutting auth, headers, retries and timeouts apply across frameworks.
HttpClient Options
5WithMiddleware()Generate middleware infrastructure (ApiDelegatingHandler + ServiceCollectionExtensions AddApiClients) for DI registration. Required to route auth / header injection through a DelegatingHandler.WithValidationAnnotations()Emit System.ComponentModel.DataAnnotations attributes ([Required], [StringLength], [Range], [EmailAddress], [RegularExpression]) on models from spec constraints (required, minLength/maxLength, minimum/maximum, format: email, pattern)WithDocumentation()Emit XML doc comments (///) on methods and parameters from schema descriptions and examplesWithMethodNames(Func)Custom method naming rule with access to operation contextWithOptionsObjectThreshold(int)Parameter count at which a method collapses its parameters into an options object (default: 4)
Auth · Headers · Resilience
11WithErrorHandling()Smart error handling on HttpClient based on HTTP status semantics (404 / 403 → null · 400 / 422 / 409 → error body · 401 / 500 / 502 / 503 → throw)WithErrorHandling(errors => errors...)Per-status routing from a clean slate: ReturnNullFor(404, 403) · ReturnErrorFor(400, 422) · ThrowFor(401, 500)WithBearerAuth()Bearer token from env var (default API_TOKEN) — adds an Authorization header to all requestsWithBearerAuth(string)Bearer token from a specific env var nameWithBearerAuth(string, string)Bearer token with custom header name (e.g. X-Api-Key)WithBasicAuth()HTTP Basic auth from default env vars (API_USERNAME / API_PASSWORD) — Base64-encoded Authorization headerWithBasicAuth(string, string)HTTP Basic auth from custom username + password env varsWithCustomHeader(string, string)Static header from env var. Repeatable (e.g. X-Tenant-ID ← TENANT_ID)WithRetries()Retries with exponential backoff (default 3 attempts, base 0.5s / max 30s, status 429, 503)WithRetries(int)Retries with a custom max-attempts countWithRetries(int, double, double, int[])Retries with full custom settings: max attempts · base delay (s) · max delay (s) · trigger status codes
OpenAPI Filtering
3WithStrictValidation()Enable strict OpenAPI validationWithOperationFilter(Func)Filter operations by predicateWithHeaderFilter(Func)Filter header parameters
Naming Transformations
3Types(Func)Transform type namesPaths(Func)Transform output pathsFileNames(Func)Transform file names
File Management
5CleanDestination()Clean output directory before generationAlwaysOverwrite()Always overwrite existing filesOnlyWhenModelChanged()Update only when model changesOnlyWhenNew()Write only new files, preserve existingCleanDirectories(...)Clean specific subdirectories
Diagnostics
2Verbose()Enable verbose loggingWithLogger(Action<string>)Route generation log output to a custom sink