Générateur de Client API Axios TypeScript depuis OpenAPI et Swagger
Générez des fonctions de client HTTP Axios sécurisées et typées ainsi que des interfaces de paramètres à partir de spécifications OpenAPI 3.0 et Swagger JSON/YAML.
/**
* 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;
};
Traitement Local Côté Client
Analyse instantanée des spécifications OpenAPI 3.0/3.1 et Swagger 2.0 avec génération TypeScript entièrement en mémoire navigateur.
Zéro Envoi vers un Serveur
Vos schémas d'API confidentiels et contrats internes ne quittent jamais votre machine. Confidentialité totale.
TypeScript Prêt pour la Production
Fonctions fortement typées, interfaces de paramètres et intercepteurs prêts à l'emploi dans vos projets React, Vue ou Node.