axigen
v1.3.0
Published
Generate typed Axios client functions from OpenAPI / Swagger specs
Maintainers
Readme
axigen
Generate typed Axios client functions from your OpenAPI / Swagger spec — in one command.
Overview
axigen reads your OpenAPI (or Swagger) spec and generates fully-typed Axios wrapper functions, so you never have to write boilerplate API calls by hand again.
- ✅ Supports OpenAPI 3.x and Swagger 2.x (YAML or JSON)
- ✅ Generates typed request/response interfaces
- ✅ Works with your own Axios instance
- ✅ TypeScript and JavaScript output
- ✅ JSDoc comments from your spec's summaries
- ✅ Filter endpoints by tag
- ✅ Zero runtime dependencies in generated code
Installation
npm install -D axigen
# or
pnpm add -D axigen
# or
yarn add -D axigenQuick Start
1. Create a config file:
npx axigen init2. Edit axigen.config.js:
/** @type {import('axigen').AxigenConfig} */
module.exports = {
// Path to your OpenAPI spec (YAML or JSON)
input: "./openapi.yaml",
output: {
// Generated Axios client functions
client: "./src/api/client.ts",
// Generated TypeScript types
types: "./src/api/types.ts",
},
// Import path to your Axios instance inside your project
axiosInstancePath: "../lib/axios",
axiosInstanceExport: "axiosInstance",
language: "ts",
jsdoc: true,
functionName: {
transforms: [{ match: "-([a-zA-Z])", flags: "g", replacement: "upper:$1" }],
appendMethod: ["post", "put", "delete", "patch", "get", "head", "options"],
},
};3. Run:
npx axigen generate
# or simply:
npx axigenExample
Given this OpenAPI spec:
paths:
/users:
get:
operationId: getUsers
summary: Get user list
tags: [users]
parameters:
- name: page
in: query
schema:
type: integer
- name: limit
in: query
schema:
type: integer
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/User"
total:
type: integer
/users/{userId}:
get:
operationId: getUserById
summary: Get user by ID
tags: [users]
parameters:
- name: userId
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/User"axigen generates:
// This file is auto-generated by axigen. DO NOT EDIT.
// Generated at: 2026-06-26T11:56:19.002Z
import type { AxiosRequestConfig, AxiosResponse } from "axios";
import { axiosInstance } from "../lib/axios";
import type { GetUserByIdPathParams, GetUserByIdResponse, GetUsersQueryParams, GetUsersResponse } from "./types";
/**
* Get user list
* `GET /users`
* @tags users
*/
export async function getGetUsers(
params?: GetUsersQueryParams,
config?: AxiosRequestConfig,
options?: AxiosRequestConfig,
): Promise<AxiosResponse<GetUsersResponse>> {
const mergedConfig: AxiosRequestConfig = { ...config, params: { ...params, ...config?.params } };
return axiosInstance({ method: "GET", url: "/users", ...mergedConfig }, options);
}
/**
* Get user by ID
* `GET /users/{userId}`
* @tags users
*/
export async function getGetUserById(
userId: GetUserByIdPathParams["userId"],
config?: AxiosRequestConfig,
options?: AxiosRequestConfig,
): Promise<AxiosResponse<GetUserByIdResponse>> {
return axiosInstance({ method: "GET", url: `/users/${userId}`, ...config }, options);
}Configuration
| Option | Type | Default | Description |
| --------------------------- | -------------- | --------------- | ------------------------------------------------------------------------ |
| input | string | — | Path to your OpenAPI spec file (YAML or JSON) |
| output.client | string | — | Output path for the generated client functions |
| output.types | string | — | Output path for generated TypeScript types (optional) |
| axiosInstancePath | string | — | Import path to your Axios instance |
| axiosInstanceExport | string | axiosInstance | Named export of your Axios instance |
| language | 'ts' \| 'js' | 'ts' | Output language |
| jsdoc | boolean | true | Add JSDoc comments to generated functions |
| tags | string[] | — | Only generate endpoints matching these tags |
| functionName | object | — | Control generated function name transforms and method suffix (see below) |
| functionName.transforms | Transform[] | [] | Array of regex transform rules applied to the operationId |
| functionName.appendMethod | string[] | [] | HTTP methods whose name is appended as a suffix to the function name |
Axios Instance
axigen does not create an Axios instance for you — it imports the one you already have in your project. The generated functions expect your instance to follow this call signature:
axiosInstance(config: AxiosRequestConfig, options?: AxiosRequestConfig): Promise<AxiosResponse>This is intentional: it lets you intercept or merge options at the instance level (e.g. passing per-request auth headers or timeout overrides as a second argument), keeping generated code decoupled from your instance's internal logic.
A typical instance looks like this:
// src/lib/axios.ts
import axios, { type AxiosRequestConfig } from "axios";
const instance = axios.create({
baseURL: "https://api.example.com/v1",
headers: {
"Content-Type": "application/json",
},
});
export const axiosInstance = (config: AxiosRequestConfig, options?: AxiosRequestConfig) => instance({ ...config, ...options });Then in your config:
axiosInstancePath: '../lib/axios',
axiosInstanceExport: 'axiosInstance', // default, can be omittedNote: If you use a plain
axios.create()instance without the two-argument wrapper, theoptionsparameter passed by generated functions will be ignored. The wrapper pattern above is the recommended approach.
CLI
# Generate client from config (default command)
axigen generate [--config <path>] [--cwd <path>]
# Create a starter config file
axigen init
# Show version
axigen --version
# Show help
axigen --helpProgrammatic Usage
You can also use axigen directly in Node.js scripts:
import { generate, loadConfig } from "axigen";
const config = await loadConfig(process.cwd());
const result = await generate(config, process.cwd());
console.log(`✓ Generated ${result.endpointCount} endpoints`);
console.log(` client → ${result.clientPath}`);
console.log(` types → ${result.typesPath}`);License
MIT
