Programmatic API
Generate from code instead of the CLI.
In addition to the CLI, you can drive the generator from code with
generateFromConfig and generate.
Usage
import { generateFromConfig, generate } from "swagger-to-tanstack-query";
// read swagger-to-tanstack-query.config.json from cwdawait generateFromConfig();
// or pass a fully-resolved configawait generate({ url: "https://api.example.com/v3/api-docs", output: "./src/api", outputDir: "/abs/path/src/api", client: { path: "@/lib/axios", name: "axiosInstance" }, response: { dataField: "data", envelope: { path: "@/lib/axios", name: "CommonResponse" } }, error: { path: "@/lib/axios", name: "ApiError" }, format: true,});generateFromConfig()readsswagger-to-tanstack-query.config.jsonfrom the current working directory — the same behavior as the CLI.generate(config)takes a fully-resolved config, including an absoluteoutputDir.
Related
- Configuration — what each field means.
- Quick Start — the CLI flow.