Getting Started
Learn how to install and use swagger-to-tanstack to generate TypeScript code from your OpenAPI specifications in just a few minutes.
Prerequisites
Installation
Install the CLI globally using your preferred package manager:
npm
yarn
pnpm
Quick Start
Step 1: Initialize Your Project
Create the required boilerplate files:
This creates:
lib/axios.ts- Axios instance configurationlib/query-keys.ts- Query keys factory for TanStack Query
Step 2: Generate Your API Client
Generate TypeScript code from your Swagger specification:
-i https://api.example.com/swagger.jsonStep 3: Install Required Dependencies
Install the necessary packages for your chosen template:
TanStack Query (default)
RTK Query
SWR
Generated Project Structure
After generation, your project will have this structure:
Using Generated Code
With TanStack Query
Import and use the generated hooks in your React components:
Setup Query Provider
Wrap your app with the QueryClientProvider:
Common Use Cases
Generate Specific Tags Only
Use Different Template
Use Fetch Instead of Axios
Watch Mode for Development
Development Workflow
Option 1: Watch Mode (Recommended for Development)
Automatically regenerate when your Swagger file changes. Preserves your modifications automatically.
✅ Safe: Skips files with custom modifications
Option 2: Update Mode (Recommended for Production)
Safely update generated files while preserving your modifications. Best for CI/CD pipelines.
✅ Safe: Always preserves modifications
Option 3: Fresh Generation
Completely regenerate everything. Use this for first-time setup or when you want to start fresh.
⚠️ Warning: Overwrites ALL files including modifications
Protecting Your Modifications
When you customize generated files, protect them by adding a comment marker:
Supported markers: // CUSTOM, // MODIFIED, // TODO, // KEEP, // USER:
Learn more about preserving modifications →
Validation
Validate your Swagger spec before generation:
This command checks if your specification is valid and displays useful information about your API.
Next Steps
Now that you have the basics down, explore more advanced features:
- Explore all available CLI commands
- Learn about different templates and when to use them
- Deep dive into CLI options and configuration
- Check out frequently asked questions
Need Help?
If you run into any issues or have questions, check out our comprehensive CLI reference or explore the example projects.