Skip to content

Configuration

Every field in swagger-to-tanstack-query.config.json explained.

The config file swagger-to-tanstack-query.config.json is read from the directory where the command runs (your project root).

Full example

{
// Swagger/OpenAPI document URL (a local file path also works).
"url": "https://api.example.com/v3/api-docs",
// Output directory, relative to cwd. Wiped & regenerated on every run.
"output": "./src/api",
// Your axios instance.
"client": {
"path": "@/lib/axios", // import path written verbatim into generated files
"name": "axiosInstance" // named export; omit (or "default") for a default import
},
// Optional: common success-envelope handling.
// `envelope` reuses one generic CommonResponse<T> instead of per-endpoint interfaces.
"response": {
"dataField": "data",
"envelope": { "path": "@/lib/axios", "name": "CommonResponse" }
},
// Optional: common error type, applied as AxiosError<T> to hooks.
"error": { "path": "@/lib/axios", "name": "ApiError" },
// Optional: run Prettier on output. Default true.
"format": true
}

Fields

FieldTypeRequiredDefaultDescription
urlstringSwagger/OpenAPI document URL or local path. Swagger 2.0 & OpenAPI 3.x.
outputstringOutput directory (relative to cwd). Wiped & regenerated every run.
client.pathstringImport path of your axios instance module.
client.namestring"default"Named export to import. Omit for a default export.
response.dataFieldstring(off)Unwrap this envelope field as the payload. See Response Envelope.
response.envelopeobject(off){ path, name } of a generic envelope type → Envelope<Inner>. Requires dataField.
error.pathstringImport path of your error-body type. See Error Type.
error.namestring"default"Named export of the error type. Omit for a default export.
formatbooleantrueFormat generated files with Prettier.

client.name behavior

The name controls whether a named or default import is written into the generated apis.ts:

ConfigGenerated import in apis.ts
{ "path": "@/lib/axios", "name": "axiosInstance" }import { axiosInstance as client } from "@/lib/axios";
{ "path": "@/lib/axios" } (no name)import client from "@/lib/axios";