OpenAPI & Swagger to Axios TypeScript API Client Generator
Generate clean, type-safe Axios HTTP client functions and parameter interfaces from OpenAPI 3.0 and Swagger JSON/YAML specs.
/**
* Swagger Petstore (v1.0.0)
* Sample store API with pets, inventories, and orders for testing Axios client generation.
* Generated by ToolsAA OpenAPI to Axios Generator
*/
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
DEFAULT_BASE_URL = 'https://petstore.swagger.io/v2';
apiClient: AxiosInstance = axios.create({
baseURL: DEFAULT_BASE_URL,
timeout: 15000,
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
});
// ============================================================================
// Data Models & Interfaces
// ============================================================================
Category {
id?: number;
name?: string;
}
Tag {
id?: number;
name?: string;
}
Pet {
id: number;
name: string;
category?: Category;
photoUrls?: string[];
tags?: Tag[];
status?: 'available' | 'pending' | 'sold';
}
NewPet {
name: string;
category?: Category;
status?: 'available' | 'pending' | 'sold';
}
Order {
id?: number;
petId?: number;
quantity?: number;
shipDate?: string;
status?: 'placed' | 'approved' | 'delivered';
complete?: boolean;
}
// ============================================================================
// Parameter Types
// ============================================================================
ListPetsQueryParams {
/** How many items to return at one time (max 100) */
limit?: number;
/** Status values that need to be considered for filter */
status?: 'available' | 'pending' | 'sold';
}
// ============================================================================
// API Operations
// ============================================================================
/**
* List all pets
* Returns a paginated list of pets filtered by availability status.
* @route GET /pets
* @param params Query parameters
*/
listPets = async (
params?: ListPetsQueryParams,
config?: AxiosRequestConfig
): Promise<Pet[]> => {
const response = await apiClient.get<Pet[]>('/pets', { params, ...config });
return response.data;
};
/**
* Create a pet
* Add a new pet to the store inventory.
* @route POST /pets
* @param data Request payload
*/
createPet = async (
data: NewPet,
config?: AxiosRequestConfig
): Promise<Pet> => {
const response = await apiClient.post<Pet>('/pets', data, { ...config });
return response.data;
};
/**
* Find pet by ID
* Returns a single pet matching the ID.
* @route GET /pets/{petId}
* @param petId The id of the pet to retrieve
*/
getPetById = async (
petId: number,
config?: AxiosRequestConfig
): Promise<Pet> => {
const response = await apiClient.get<Pet>(`/pets/${encodeURIComponent(String(petId))}`, { ...config });
return response.data;
};
/**
* Update pet by ID
* Updates attributes of an existing pet record.
* @route PUT /pets/{petId}
* @param petId Path parameter
* @param data Request payload
*/
updatePetById = async (
petId: number,
data: NewPet,
config?: AxiosRequestConfig
): Promise<Pet> => {
const response = await apiClient.put<Pet>(`/pets/${encodeURIComponent(String(petId))}`, data, { ...config });
return response.data;
};
/**
* Delete pet by ID
* Deletes a pet record from database.
* @route DELETE /pets/{petId}
* @param petId Path parameter
*/
deletePetById = async (
petId: number,
config?: AxiosRequestConfig
): Promise<void> => {
const response = await apiClient.delete<void>(`/pets/${encodeURIComponent(String(petId))}`, { ...config });
return response.data;
};
/**
* Place an order
* Place an order for purchasing a pet.
* @route POST /store/orders
* @param data Request payload
*/
placeOrder = async (
data: Order,
config?: AxiosRequestConfig
): Promise<Order> => {
const response = await apiClient.post<Order>('/store/orders', data, { ...config });
return response.data;
};
/**
* Find purchase order by ID
* @route GET /store/orders/{orderId}
* @param orderId Path parameter
*/
getOrderById = async (
orderId: number,
config?: AxiosRequestConfig
): Promise<Order> => {
const response = await apiClient.get<Order>(`/store/orders/${encodeURIComponent(String(orderId))}`, { ...config });
return response.data;
};
Zero-Knowledge Local Execution
Instant OpenAPI 3.0/3.1 and Swagger 2.0 parsing and Axios TypeScript code generation executed entirely in browser memory.
Sub-Millisecond AST Engine
Proprietary API schemas, internal routes, and confidential contracts never leave your machine. 100% zero-server privacy.
Production-Ready TypeScript
Clean, strongly typed Axios functions, parameter interfaces, and interceptors ready for immediate copy-paste into frontend and Node services.