{"id":48840,"library":"openapi-axios","title":"openapi-axios","description":"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.","status":"active","version":"0.34.0","language":"javascript","source_language":"en","source_url":"https://github.com/FrontEndDev-org/openapi-axios","tags":["javascript","cloudcome","ydr.me","OpenAPI","swagger","TypeScript","OAS","axios","typescript"],"install":[{"cmd":"npm install openapi-axios","lang":"bash","label":"npm"},{"cmd":"yarn add openapi-axios","lang":"bash","label":"yarn"},{"cmd":"pnpm add openapi-axios","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime peer dependency for making HTTP requests","package":"axios","optional":false},{"reason":"Optional dependency for request/response validation","package":"zod","optional":true}],"imports":[{"note":"defineConfig is a named export from the main package, not a subpath. Available since v0.1.0.","wrong":"import { defineConfig } from 'openapi-axios/client'","symbol":"defineConfig","correct":"import { defineConfig } from 'openapi-axios'"},{"note":"OpenAPIAxios is the class for programmatic usage, exported from the main entry point. Do not import from lib/* paths.","wrong":"import { OpenAPIAxios } from 'openapi-axios/lib'","symbol":"OpenAPIAxios","correct":"import { OpenAPIAxios } from 'openapi-axios'"},{"note":"GenerateOptions is a TypeScript type; use type import to avoid runtime bundling.","wrong":"import { GenerateOptions } from 'openapi-axios'","symbol":"GenerateOptions","correct":"import type { GenerateOptions } from 'openapi-axios'"}],"quickstart":{"code":"// openapi.config.cjs\nconst { defineConfig } = require('openapi-axios');\nmodule.exports = defineConfig({\n  documents: {\n    petStore: 'https://petstore3.swagger.io/api/v3/openapi.json'\n  }\n});\n// Run: npx openapi-axios\n// Generated: src/apis/petStore.ts, src/apis/petStore.type.ts\n\n// src/app.ts\nimport axios from 'axios';\nimport { addPet } from './apis/petStore';\nimport type { AddPetData } from './apis/petStore.type';\n\nconst newPet: AddPetData = {\n  name: 'Fluffy',\n  photoUrls: ['https://example.com/fluffy.jpg']\n};\n\naddPet(newPet).then(response => {\n  console.log('Pet created:', response.data);\n}).catch(err => {\n  console.error('Failed to add pet:', err);\n});\n","lang":"typescript","description":"Initializes a config file, generates type-safe Axios functions from an OpenAPI spec, then uses the generated addPet function with full type checking."},"warnings":[{"fix":"Use the programmatic API with a custom Axios instance: new OpenAPIAxios({ axiosInstance: customAxios }).","message":"The generated code uses axios imported from 'axios' (default import). If you have a different Axios instance, you may need to configure the generated files manually or use the programmatic API.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Manually create openapi.config.cjs or openapi.config.js using defineConfig().","message":"The 'init' command is deprecated in favor of manual config creation. Running 'npx openapi-axios init' may be removed in a future major version.","severity":"deprecated","affected_versions":">=0.30.0"},{"fix":"Always use TypeScript to get the full benefit of the library.","message":"The generated functions return axios response types, but the actual data shape is typed via generics. If you skip TypeScript, you lose type safety.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Wrap calls in try-catch that handles both AxiosError and ZodError, or disable validation.","message":"When using Zod validation, the generated request functions will throw a ZodError on validation failure. This may not be caught if you only handle Axios errors.","severity":"gotcha","affected_versions":">=0.20.0"}],"env_vars":null,"search_vec":"'/3.0/3.1':11 '0.34.0':27 '2.0':10 'api':51 'axio':3,17,69,84 'built':49 'built-in':48 'cadenc':32 'capabl':53 'cloudcom':78 'code':5 'continu':31 'convert':8 'current':23 'differenti':34 'enabl':70 'file':46 'full':20 'function':18,64 'generat':6,43,60 'includ':35 'integr':66 'intermedi':44 'javascript':77 'key':33 'mock':52 'oa':83 'openapi':2,9,57,80 'openapi-axio':1 'option':36 'releas':28 'request':63 'request/response':37 'safe':16 'safeti':76 'schema':45 'seamless':67 'shake':73 'spec':58 'specif':12 'stabl':24 'strong':61 'support':22,41 'swagger':81 'tree':72 'tree-shak':71 'type':15,62,75 'type-saf':14 'typescript':21,82,85 'use':55 'valid':38 'version':25 'via':39 'ydr.me':79 'zod':40","created_at":"2026-06-07T16:58:44.139611+00:00","updated_at":"2026-06-07T16:58:44.139611+00:00","problems":[{"fix":"Ensure openapi-axios is in devDependencies and run `npm install`. For TypeScript, add `moduleResolution: 'node'` in tsconfig.json.","cause":"The package is installed as a dev dependency but not built or imported correctly.","error":"Cannot find module 'openapi-axios' or its corresponding type declarations."},{"fix":"Use a .cjs extension or use ES module syntax. The package exports both ESM and CJS via module/require fields.","cause":"Using require() on the ES module version of the package.","error":"TypeError: defineConfig is not a function"},{"fix":"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.","cause":"Running 'npx openapi-axios init' while not having a config file already.","error":"The 'init' command requires a file named 'openapi.config.cjs' to be present."},{"fix":"Install axios as a regular dependency: npm install axios","cause":"axios is a required peer dependency but not listed as a regular dependency.","error":"Cannot generate files because axios is not installed."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/FrontEndDev-org/openapi-axios","github":"https://github.com/FrontEndDev-org/openapi-axios","docs":null,"changelog":null,"pypi":null,"npm":"openapi-axios","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}