npm NuGet v1.2.1 MIT
@metaengine/openapi-react
OpenAPI 3.x → React hooks with TanStack Query (useQuery, useMutation) and native Fetch API. Tree-shakeable, typed, React 18+.
Install
Pick your registry
The same generator, published to every ecosystem we support. Install however your project expects.
npmPrimary@metaengine/openapi-react
$npm install @metaengine/openapi-react
v1.2.1
NuGetMetaEngine.TypeScript.OpenApi.React
$dotnet add package MetaEngine.TypeScript.OpenApi.React
v1.2.1
Usage
Drive it from the CLI or programmatically
npm ships a zero-config CLI. NuGet ships the same generator as a C# fluent API — same options, same output.
npm · npx · CI-friendly
After install, point the CLI at your schema. It writes the generated tree to your chosen output directory.
Basic syntax
npx @metaengine/openapi-react <input> <output> [options]Supports OpenAPI 3.0+ specifications in both JSON and YAML formats.
Quick examples
Generate from a local file
npx @metaengine/openapi-react api.yaml ./src/apiGenerate from a URL
npx @metaengine/openapi-react https://api.example.com/openapi.json ./src/apiWith TanStack Query and Vite
npx @metaengine/openapi-react api.yaml ./src/api \
--tanstack-query \
--documentation \
--base-url-env VITE_API_URLCLI options
Option
Description
--base-url-env <name>
Environment variable name for base URL [default: REACT_APP_API_BASE_URL]. Use VITE_ prefix for Vite, NEXT_PUBLIC_ for Next.js.
--service-suffix <suffix>
Service naming suffix [default: Api]
--tanstack-query
Enable TanStack Query integration (useQuery / useMutation)
--documentation
Generate JSDoc comments
--options-threshold <n>
Parameter count to use options object [default: 4]
--type-mapping <mapping>
Override TS type for an OpenAPI format. Repeatable. int64=bigint · decimal=string · date-time=string · date=string
--include-tags <tags>
Filter by OpenAPI tags (comma-separated, case-insensitive)
--strict-validation
Enable strict OpenAPI validation
--date-transformation
Convert date strings in responses to JavaScript Date objects
--clean
Clean output directory (remove files not in generation)
--verbose
Enable verbose logging
--help, -h
Show help message
Options reference
Every 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.
React Options
7WithBaseUrlEnvVar(string)Environment variable name for base URL (default: "REACT_APP_API_BASE_URL"). Use VITE_ prefix for Vite, NEXT_PUBLIC_ for Next.js.WithTanStackQuery()Generate TanStack Query hooks (useQuery / useMutation). Requires @tanstack/react-query.WithMiddleware()Emit onRequest / onResponse / onError middleware hooks in the generated clientWithResponseDateTransformation()Convert date / date-time strings in responses to Date objectsWithMethodNames(Func)Custom method naming ruleWithDocumentation()Enable JSDoc commentsWithOptionsObjectThreshold(int)Parameter count for options object (default: 4)
Auth · Headers · Resilience
12WithErrorHandling()Enable smart error handling based on HTTP status semanticsWithErrorHandling(errors => errors...)Per-status routing: ReturnNullFor(404, 403) · ReturnErrorFor(400, 422) · ThrowFor(401, 500)WithBearerAuth()Bearer token from env var (default API_TOKEN) — adds Authorization headerWithBearerAuth(string)Bearer token from a specific env var nameWithBearerAuth(string, string)Bearer token with custom header nameWithBasicAuth(string, string)HTTP Basic auth from username + password env varsWithCustomHeader(string, string)Static header from env var. Repeatable.WithTimeout(double)Request timeout in seconds for all operationsWithTimeout(double?, double?, double?, double?)Granular timeout: seconds · connect · read · writeWithRetries()Retries with exponential backoff (default status 429, 503)WithRetries(int)Retries with a custom max-attempts countWithRetries(int, double, double, int[])Retries with full custom settings including 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
Features
Why this package is different
Tree-shakeable
One file per tag (or per operation) means bundlers drop unused clients at build time. No runtime dispatch table.
Strict, no any
Output compiles under strict with no any. Unions, nullability and enums are modelled precisely so tsc catches drift.
Zero runtime
The default emit is types plus a thin client — no decorators, no reflection, no dependency surface beyond your HTTP lib.
Deterministic output
Same spec + same options produce byte-identical files. Safe to commit, safe to diff in review, safe to cache in CI.
Flexible naming
Case conventions are configurable per role — types, properties, operations, enums. Idiomatic in the target by default.
Semver-honest
Spec diff drives the version bump. Additive changes = minor, removed operations = major. Never a surprise in your lockfile.