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-axiosVerified import paths — ran on the pinned version, not inferred.
Initializes an OpenAPI client with a public Petstore definition, then demonstrates fetching existing data and creating new resources using the dynamically generated client methods.
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.
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`.
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"`).
Change your import statement from `const OpenAPIClientAxios = require('openapi-client-axios');` to `const OpenAPIClientAxios = require('openapi-client-axios').default;`.Modify your import to `const OpenAPIClientAxios = require('openapi-client-axios').default;`.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 })`.Replace `require()` with the standard ES Module `import` syntax: `import OpenAPIClientAxios from 'openapi-client-axios';`.