Skip to content

CLI Reference

Swaggie is invoked via the swaggie command. All options can be provided via flags or via a configuration file.

Synopsis

bash
swaggie [options]

At minimum, you need either --config or --src:

bash
# Using a config file
swaggie -c swaggie.config.json

# Using flags directly
swaggie -s <spec-url-or-path> -o <output-file>

Options

FlagAliasTypeDefaultDescription
--config-cstringPath to a JSON configuration file. Mutually exclusive with --src.
--src-sstringURL or file path to the OpenAPI spec (.json or .yaml). Required when not using --config.
--out-ostringOutput file path. Omit to print generated code to stdout.
--template-tstringaxiosTemplate to use. HTTP client templates: axios, fetch, xior, ng1, ng2. Reactive layer templates paired with an HTTP client using a comma-separated value: swr,axios / tsq,xior / swr,fetch, etc. A reactive layer name alone (e.g. swr) defaults to fetch as the HTTP client. A path to a custom template directory is also accepted.
--baseUrl-bstring""Default base URL baked into the generated client.
--mode-mstringfullGeneration mode: full (client + schemas) or schemas (types only).
--schemaStyle-dstringinterfaceSchema object style: interface or type.
--enumStylestringunionEnum declaration style: union or enum.
--enumNamesStylestringoriginalEnum member name formatting: original, PascalCase, or pascal. Only with --enumStyle enum.
--dateFormatstringDateTypeScript type for date fields: Date or string.
--nullablesstringignoreNullable handling: ignore, include, or nullableAsOptional.
--preferAnybooleanfalseUse any instead of unknown for untyped values.
--skipDeprecatedbooleanfalseExclude deprecated operations from the output.
--servicePrefixstring""Prefix for generated service (client object) names.
--allowDotsbooleantrueUse dot notation for nested object query params (a.b=1 vs a[b]=1).
--arrayFormatstringrepeatArray serialization in query strings: indices, repeat, or brackets.
--queryParamsAsObjectboolean | numberGroup all query parameters into a single typed object argument. Pass without a value to always group, or pass a number N to group only when there are more than N query parameters. See Query Parameter Grouping.
--useClient-CbooleanfalsePrepend 'use client'; as the first line of the generated file. Required for Next.js App Router when using swr or tsq templates. Has no effect and should not be used outside of RSC environments.
--mocksstringOutput path for the generated mock/stub file. Requires --testingFramework and --out. See Mocking.
--testingFramework-TstringTest framework for generated mock stubs: vitest or jest. Requires --mocks and --out.
--version-VPrint the installed version number and exit.
--help-hShow the help message and exit.

Examples

Minimal — output to stdout

bash
swaggie -s https://petstore3.swagger.io/api/v3/openapi.json

The generated TypeScript is printed to stdout. Useful for piping:

bash
swaggie -s ./spec.json | prettier --parser typescript > ./src/api/client.ts

Minimal — write to file

bash
swaggie -s https://petstore3.swagger.io/api/v3/openapi.json -o ./src/api/client.ts

With config file

bash
swaggie -c swaggie.config.json

Override config file options via flags

CLI flags take precedence over config file values. This lets you override specific settings at call time:

bash
swaggie -c swaggie.config.json --template fetch --out ./src/api/client-fetch.ts

Generate only TypeScript schemas

bash
swaggie -s ./spec.json -o ./src/types.ts --mode schemas

Use the fetch template with dot-notation query params

bash
swaggie -s ./spec.json -o ./client.ts -t fetch --allowDots --arrayFormat repeat

Use a reactive query layer with a specific HTTP client

Combine a reactive query layer template with an HTTP client template using a comma-separated pair:

bash
# SWR hooks backed by axios
swaggie -s ./spec.json -o ./client.ts -t swr,axios

# TanStack Query hooks backed by xior
swaggie -s ./spec.json -o ./client.ts -t tsq,xior

# SWR hooks backed by the native fetch API
swaggie -s ./spec.json -o ./client.ts -t swr,fetch

Skip deprecated endpoints

bash
swaggie -s ./spec.json -o ./client.ts --skipDeprecated

Next.js App Router (SWR or TanStack Query)

SWR and TanStack Query hooks can only run in Client Components. Use --useClient (or -C) to prepend the required 'use client'; directive:

bash
swaggie -s ./spec.json -o ./src/api/client.ts -t swr,axios --useClient
swaggie -s ./spec.json -o ./src/api/client.ts -t tsq,fetch -C

Or in a config file:

json
{
  "src": "./spec.json",
  "out": "./src/api/client.ts",
  "template": ["swr", "axios"],
  "useClient": true
}

Piping to a formatter

Swaggie's output is functional but may not match your project's whitespace style. Pipe it through a formatter as part of your workflow:

bash
# Prettier
swaggie -c swaggie.config.json && prettier ./src/api/client.ts --write

# Biome
swaggie -c swaggie.config.json && biome check ./src/api/client.ts --write

Exit codes

CodeMeaning
0Success
1Error — invalid options, spec load failure, generation error

Released under the MIT License.