Registry / http-networking / openapi-client-axios

openapi-client-axios

JSON →
library7.9.0jsnpmunverified

openapi-client-axios is a JavaScript and TypeScript library designed to create dynamic API clients from OpenAPI v3 definitions at runtime. It leverages the popular axios library for HTTP requests, offering a powerful and flexible alternative to code generation for API consumption. The current stable version is 7.9.0. The library features automatic TypeScript type generation for API operations, full IntelliSense support, and a consistent API for calling operations using JavaScript methods based on operationIds. It operates isothermically in both browser and Node.js environments. Key differentiators include its no-code-generation approach, strong TypeScript integration, and reliance on existing, robust HTTP client infrastructure (axios), providing a predictable release cadence tied to upstream OpenAPI spec updates and axios releases.

npm install openapi-client-axios
INSTALL
IMPORT
SIG · OPENAPI-CLIENT-AXI
O
openapi-client-axios
http-networkingjavascriptv7.9.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpenAPIClientAxios
import OpenAPIClientAxios from 'openapi-client-axios';
import { OpenAPIClientAxios } from 'openapi-client-axios';
The primary class constructor is exported as a default export. For CommonJS environments, use `require('openapi-client-axios').default`.
Client
import type { Client } from 'openapi-client-axios';
Type definition for the dynamically generated API client instance returned by `api.getClient()` or resolved by `api.init()`.
OpenAPIClient
import type { OpenAPIClient } from 'openapi-client-axios';
Type definition for the main OpenAPIClientAxios instance itself, useful when working with the API configuration.

Initializes an OpenAPI client with a public Petstore definition, then demonstrates fetching existing data and creating new resources using the dynamically generated client methods.

import OpenAPIClientAxios from 'openapi-client-axios'; import type { Client } from 'openapi-client-axios'; const PETSTORE_URL = 'https://petstore.swagger.io/v2/swagger.json'; // Initialize the client with the OpenAPI definition URL const api = new OpenAPIClientAxios({ definition: PETSTORE_URL }); async function fetchAndCreatePet() { try { // Initialize the API client and get the generated operations const client: Client = await api.getClient(); // Example 1: Fetch all pets (using a method derived from operationId 'findPetsByStatus') console.log('Fetching available pets...'); const availablePetsResponse = await client.findPetsByStatus({ status: ['available'] }); console.log('Available pets:', availablePetsResponse.data.slice(0, 3)); // Log first 3 // Example 2: Create a new pet (using operationId 'addPet') console.log('\nAdding a new pet...'); const newPet = { id: 987654321, name: 'Buddy', status: 'available', category: { id: 1, name: 'Dogs' }, photoUrls: ['http://example.com/buddy.jpg'] }; const addPetResponse = await client.addPet(newPet); console.log('New pet added:', addPetResponse.data); } catch (error: any) { console.error('An error occurred:', error.message); if (error.response) { console.error('API Response Data:', error.response.data); } } } fetchAndCreatePet();
Debug
Known issues
breakingSince v7.0.0, `openapi-client-axios` no longer supports resolving remote `$refs` or loading OpenAPI definitions from local file paths. Definitions must be provided as local URLs or inline JavaScript/JSON objects.
fix
Ensure your OpenAPI definition is accessible via a URL (e.g., `https://example.com/api/openapi.json`) or loaded into memory as a JavaScript object before being passed to the `definition` option. Resolve all `$refs` internally or manually if they point to remote locations.
affects: >=7.0.0
breakingVersion 7.0.0 removed the `@apidevtools/swagger-parser` dependency, replacing it with an internal, simpler dereferencer. This change significantly reduces bundle size but means custom parsing or complex `$ref` resolution strategies previously relying on `swagger-parser` may no longer work.
fix
If you relied on specific features or behaviors of `swagger-parser`, you may need to pre-process your OpenAPI definition externally before passing it to `openapi-client-axios`.
affects: >=7.0.0
breakingVersion 6.0.0 introduced support for `axios` v1 and above. Older versions of `axios` might lead to compatibility issues or unexpected behavior.
fix
Upgrade your `axios` dependency to version 1.x or later. Ensure your project's `package.json` reflects a compatible `axios` version (e.g., `"axios": ">=1.0.0"`).
affects: >=6.0.0
gotchaWhen using `openapi-client-axios` in a CommonJS environment (e.g., Node.js without ESM enabled), the `OpenAPIClientAxios` class is exposed as a default export, requiring `.default` to access.
fix
Change your import statement from `const OpenAPIClientAxios = require('openapi-client-axios');` to `const OpenAPIClientAxios = require('openapi-client-axios').default;`.
affects: *
Errors
Common errors & fixes
Cannot read properties of undefined (reading 'default')
Attempting to use `require('openapi-client-axios')` directly in CommonJS without accessing the default export of the module.
fix
Modify your import to `const OpenAPIClientAxios = require('openapi-client-axios').default;`.
Error: definition must be a string (URL) or an object
Passing a local file path (e.g., `./openapi.json`) as the `definition` option, which is no longer supported for file system resolution since v7.0.0.
fix
Provide a URL for the OpenAPI definition, or read the file content yourself and pass the parsed JSON/YAML object directly: `new OpenAPIClientAxios({ definition: yourParsedObject })`.
ReferenceError: require is not defined in ES module scope
Using CommonJS `require()` syntax in an environment configured for ES Modules (e.g., Node.js with `"type": "module"` in `package.json` or in a browser bundling context expecting ESM).
fix
Replace `require()` with the standard ES Module `import` syntax: `import OpenAPIClientAxios from 'openapi-client-axios';`.
Upgrade
Version history
7.9.0latest on npm
Audit
Dependencies
axiosrequiredRequired for making HTTP requests to the API.
js-yamlrequiredNeeded for parsing YAML-formatted OpenAPI definitions.
Agent activity
4 hits · last 30 days
node
4
Resources