S2T

generate

Generate TypeScript code from your Swagger/OpenAPI specification. This is the main command for creating your API client.

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

Generate with default settings (TanStack Query + Axios + Zod)

bash

Custom output directory

Specify a custom output location

bash

Using RTK Query template

Generate with Redux Toolkit Query

bash

Filter by tags

Only generate specific endpoints

bash

From URL with authentication

Fetch Swagger spec from a protected URL

bash

Important Notes

Without --preserve-modified flag, this command will overwrite ALL files including your modifications. Use version control!
Use the "update" command instead if you have made custom modifications to generated files.

👋 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.