CLI Commands
Complete reference for all swagger-to-tanstack CLI commands with examples and options.
generate
Generate TypeScript code from your Swagger/OpenAPI specification
Usage
Options
-i, --input <path>Path or URL to Swagger/OpenAPI file (required)
-o, --output <dir>Output directory (default: ./src/api)
-t, --template <name>Template: tanstack-query, rtk-query, swr, react-query-kit, basic (default: tanstack-query)
--http-client <client>HTTP client: axios or fetch (default: axios)
--validator <validator>Schema validator: zod or yup (default: zod)
--strip-base-path [path]Strip base path from routes
--include-tags <tags>Only generate specific tags (comma-separated)
--exclude-tags <tags>Exclude specific tags (comma-separated)
--preserve-modifiedSkip overwriting modified files
-u, --username <username>Basic auth username
-p, --password <password>Basic auth password
Examples
Basic generation with TanStack Query
Generate with custom output directory
Using RTK Query template with fetch
Only generate specific tags
Exclude certain tags
From URL with authentication
init
Initialize project with required boilerplate files
Usage
Examples
Create lib/axios.ts and lib/query-keys.ts
watch
Watch for changes in Swagger file and regenerate automatically
Usage
Options
-i, --input <path>Local Swagger file path to watch (required)
-o, --output <dir>Output directory (default: ./src/api)
-t, --template <name>Template to use (default: tanstack-query)
--http-client <client>HTTP client: axios or fetch (default: axios)
--validator <validator>Schema validator: zod or yup (default: zod)
--strip-base-path [path]Strip base path from routes
Examples
Watch local Swagger file
Watch with custom output
Watch with RTK Query template
update
Update generated files while preserving user modifications
Usage
Options
-i, --input <path>Path or URL to Swagger/OpenAPI file (required)
-o, --output <dir>Output directory (default: ./src/api)
-t, --template <name>Template to use (default: tanstack-query)
--http-client <client>HTTP client: axios or fetch (default: axios)
--validator <validator>Schema validator: zod or yup (default: zod)
--strip-base-path [path]Strip base path from routes
--include-tags <tags>Only update specific tags (comma-separated)
--exclude-tags <tags>Exclude specific tags (comma-separated)
-u, --username <username>Basic auth username
-p, --password <password>Basic auth password
Examples
Update safely preserving modifications
Update specific tags only
Update from URL with authentication
validate
Validate Swagger/OpenAPI specification and display API info
Usage
Options
-i, --input <path>Path or URL to Swagger/OpenAPI file (required)
-u, --username <username>Basic auth username
-p, --password <password>Basic auth password
Examples
Validate local file
Validate remote spec with authentication
list-templates(list)
List all available templates, HTTP clients, and validators
Usage
Examples
Show all available options
Using alias
Workflow Recommendations
First time setup:
- Run
swagger-to-tanstack initto create boilerplate files - Run
swagger-to-tanstack generate -i ./swagger.jsonto generate your API client - Import and use generated hooks in your React components
Development workflow:
- Use
watchmode for automatic regeneration during development - Use
updatecommand when you've made custom modifications to generated files - Use
validateto check your Swagger spec before generation