S2T

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

bash

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-modified

Skip overwriting modified files

-u, --username <username>

Basic auth username

-p, --password <password>

Basic auth password

Examples

Basic generation with TanStack Query

bash

Generate with custom output directory

bash

Using RTK Query template with fetch

bash

Only generate specific tags

bash

Exclude certain tags

bash

From URL with authentication

bash

init

Initialize project with required boilerplate files

Usage

bash

Examples

Create lib/axios.ts and lib/query-keys.ts

bash
Note: Creates lib/axios.ts (Axios configuration) and lib/query-keys.ts (Query keys factory for TanStack Query)

watch

Watch for changes in Swagger file and regenerate automatically

Usage

bash

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

bash

Watch with custom output

bash

Watch with RTK Query template

bash
Note: Watch mode only works with local files. Automatically preserves user modifications.

update

Update generated files while preserving user modifications

Usage

bash

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

bash

Update specific tags only

bash

Update from URL with authentication

bash
Note: ALWAYS preserves your custom modifications. Use 'generate' for fresh generation.

validate

Validate Swagger/OpenAPI specification and display API info

Usage

bash

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

bash

Validate remote spec with authentication

bash
Note: Shows API title, version, number of paths, schemas, and available tags.

list-templates(list)

List all available templates, HTTP clients, and validators

Usage

bash

Examples

Show all available options

bash

Using alias

bash
Note: Displays detailed comparison table and recommendations for each template.

Workflow Recommendations

First time setup:

  1. Run swagger-to-tanstack init to create boilerplate files
  2. Run swagger-to-tanstack generate -i ./swagger.json to generate your API client
  3. Import and use generated hooks in your React components

Development workflow:

  • Use watch mode for automatic regeneration during development
  • Use update command when you've made custom modifications to generated files
  • Use validate to check your Swagger spec before generation

👋 Hello and welcome!

I'm Armel Dakayao, Front-End Developer & creator of swagger-to-tanstack CLI.

Armel Dakayao

Senior Front-End Developer. I build scalable, user-friendly web & mobile apps with React,React Native, Next.js, and TypeScript.