MetaEngine.TypeScript.OpenApi.React

Generate TypeScript models and React hooks from OpenAPI/Swagger specifications. Perfect for API-first development with TanStack Query integration and native Fetch API.

npm versionnpm downloadslicensenuget version
NPM Package

Use as a CLI tool via npm/npx

# Install globally
npm install -g @metaengine/openapi-react
# Or use with npx
npx @metaengine/openapi-react api.yaml ./src/api

Requirements: Node.js 18+, .NET 8.0+ runtime

NuGet Package

Use programmatically in .NET projects

# Install via dotnet CLI
dotnet add package MetaEngine.TypeScript.OpenApi.React

Requirements: .NET Standard 2.0+

Command Line Usage

Basic Syntax
npx @metaengine/openapi-react <input> <output> [options]

Supports OpenAPI 3.0+ specifications in both JSON and YAML formats.

Quick Examples
# Generate from local file
npx @metaengine/openapi-react api.yaml ./src/api
# Generate from URL
npx @metaengine/openapi-react https://api.example.com/openapi.json ./src/api
# With TanStack Query and Vite
npx @metaengine/openapi-react api.yaml ./src/api \
--tanstack-query \
--documentation \
--base-url-env VITE_API_URL
CLI Options
OptionDescription
--base-url-env <name>Environment variable name for base URL [default: REACT_APP_API_BASE_URL]
--service-suffix <suffix>Service naming suffix [default: Api]
--tanstack-queryEnable TanStack Query integration
--documentationGenerate JSDoc comments
--options-threshold <n>Parameter count to use options object [default: 4]
--include-tags <tags>Filter by OpenAPI tags (comma-separated, case-insensitive)
--strict-validationEnable strict OpenAPI validation
--verboseEnable verbose logging
--help, -hShow help message

Programmatic Usage (C#)

Configuration Example
Configuration Example

Framework Support

Generates code compatible with Vite, Next.js, and Create React App. Configure your env var prefix to match your framework.

TanStack Query

Optional integration with useQuery and useMutation hooks for reactive data fetching.

Monorepo Friendly

Configure different environment variables for multiple APIs in the same project.

Options Reference

React Options

  • WithBaseUrlEnvVar(string)Environment variable name for base URL (default: "REACT_APP_API_BASE_URL")
  • WithServiceSuffix(string)Service suffix (default: "Api")
  • WithTanStackQuery(bool)Generate TanStack Query hooks (default: false)
  • WithMethodNames(Func)Custom method naming rule
  • WithDocumentation()Enable JSDoc comments
  • WithOptionsObjectThreshold(int)Parameter count for options object (default: 4)

OpenAPI Filtering

  • WithStrictValidation()Enable strict OpenAPI validation
  • WithOperationFilter(Func)Filter operations by predicate
  • WithHeaderFilter(Func)Filter header parameters

Naming Transformations

  • Types(Func)Transform type names
  • Paths(Func)Transform output paths
  • FileNames(Func)Transform file names

File Management

  • CleanDestination()Clean output directory before generation
  • AlwaysOverwrite()Always overwrite existing files
  • OnlyWhenModelChanged()Update only when model changes
  • OnlyWhenNew()Write only new files, preserve existing
  • CleanDirectories(...)Clean specific subdirectories

Diagnostics

  • EnableVerboseLogging()Enable detailed logging