A code generator that converts OpenAPI 2.0/3.0/3.1 specifications into type-safe Axios functions with full TypeScript support. Current stable version is 0.34.0, released on a continuous cadence. Key differentiators include optional request/response validation via Zod, support for generating intermediate schema files, and built-in API mocking capabilities. It uses the OpenAPI spec to generate strongly typed request functions that integrate seamlessly with Axios, enabling tree-shaking and type safety.
npm install openapi-axiosNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initializes a config file, generates type-safe Axios functions from an OpenAPI spec, then uses the generated addPet function with full type checking.
Use the programmatic API with a custom Axios instance: new OpenAPIAxios({ axiosInstance: customAxios }).Manually create openapi.config.cjs or openapi.config.js using defineConfig().
Always use TypeScript to get the full benefit of the library.
Wrap calls in try-catch that handles both AxiosError and ZodError, or disable validation.
Ensure openapi-axios is in devDependencies and run `npm install`. For TypeScript, add `moduleResolution: 'node'` in tsconfig.json.
Use a .cjs extension or use ES module syntax. The package exports both ESM and CJS via module/require fields.
Just run 'npx openapi-axios init' without a pre-existing config; it creates one, but if you see this error, you might have a misconfigured setup. Try deleting any partial config and re-running.
Install axios as a regular dependency: npm install axios