{"_id":"@arutkowski00/openapi-client-axios","_rev":"2-c562c854ee505a49b177fefe412016de","name":"@arutkowski00/openapi-client-axios","dist-tags":{"latest":"4.1.0-patch.1"},"versions":{"4.1.0-patch.1":{"name":"@arutkowski00/openapi-client-axios","description":"JavaScript client library for consuming OpenAPI-enabled APIs with axios. Types included.","version":"4.1.0-patch.1","author":{"name":"Viljami Kuosmanen","email":"viljami@viljami.io"},"license":"MIT","keywords":["openapi","swagger","client","axios","frontend","browser","mock","typescript"],"homepage":"https://github.com/anttiviljami/openapi-client-axios","repository":{"type":"git","url":"git+https://github.com/anttiviljami/openapi-client-axios.git"},"bugs":{"url":"https://github.com/anttiviljami/openapi-client-axios/issues"},"main":"index.js","types":"index.d.ts","peerDependencies":{"axios":"^0.21.1","js-yaml":"^3.13.1"},"dependencies":{"@apidevtools/json-schema-ref-parser":"^9.0.7","bath-es5":"^3.0.3","lodash":"^4.17.20","openapi-types":"^9.0.0","query-string":"^7.0.0"},"devDependencies":{"@anttiviljami/dtsgenerator":"^2.5.1","@types/jest":"^26.0.20","@types/json-schema":"^7.0.6","@types/lodash":"^4.14.168","@types/node":"^10.12.29","@types/yargs":"^13.0.0","axios":"^0.21.1","axios-mock-adapter":"^1.16.0","indent-string":"^4.0.0","jest":"^26.6.3","json-schema":"^0.2.5","json-schema-deref-sync":"^0.13.0","markdown-toc":"^1.2.0","prettier":"^1.19.1","source-map-support":"^0.5.10","ts-jest":"^26.5.0","tslint":"^5.20.1","tslint-microsoft-contrib":"^5.2.1","typescript":"^4.1.5","yargs":"^13.2.2"},"scripts":{"build":"tsc","watch-build":"tsc -w","lint":"tslint --format prose --project .","prettier":"prettier --write src/** __tests__/**","toc":"./scripts/generate-toc.js","prepare":"npm run build","test":"NODE_ENV=test jest"},"gitHead":"831a5cc18ee20efd20e75d090d74a6017b2eea42","_id":"@arutkowski00/openapi-client-axios@4.1.0-patch.1","_nodeVersion":"10.24.1","_npmVersion":"6.14.12","dist":{"integrity":"sha512-ebghVyFO368d3ltulVxbUxpCT0h1UtVZUdFw/4WiQZCUcdoAq7sGoUhAQ8hTm+A1EtZ572whz8ZCTxr6JhvAwA==","shasum":"09a3b82c2157af9a30bfe86664371afd23e1ebf5","tarball":"https://registry.npmjs.org/@arutkowski00/openapi-client-axios/-/openapi-client-axios-4.1.0-patch.1.tgz","fileCount":9,"unpackedSize":48594,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhwzjSCRA9TVsSAnZWagAAaJ0QAJgH+FrKSxYpYi1hIkbb\n9honzuQUiuKF0GrGJz5pRKY9IHXUJZbX7LF+xWHldNhwgK6NbW8WMQwHDhU4\n05J5D6aUHAER6FEQ7abzgXOGV1JLlq2JcPggx/sEGwWILvorPjVPTs9gptwq\nOOpebXeAOoL4adthWFf0GKGPLA45hArGK8auq72cRSxqn5c0mXP7mqMHMVAC\nfe13Xcv8lYKggI+V5rDTbjlkHVvGeOKm0CZJB2Na6IGCntMABKhBNKsMaQh4\nksZEvJWzjPnXX8jpki5m4YB+1+Xdc49ZFCzUyStmP3Sc15d+gZ4GxJ1TQV3Z\n5x4AYeDq+D40Bykj97CKi7RtSLpaQDTqFJmmGeyU45sY6U3NgfZDkXoo8DIj\nrw+FOuI3qT3O0C5qOvGR94c5xinB5Oygw/n4bPRaRr3W+WnrbHUA+laGyiJ8\nc3CnJ1xS29qgps8gcUhO3a9fFTHtERg0D4w1FlQHe2k5lD3RXC4hN4wSJV9o\n+v7PZHSPOa09tcdhbo+FLDxj6smKULnY3tr1rAA/LmnGDUFzhn62HuLEjEEm\nznQsMJQ4lmh+mONckG78zbCx+zQYDUA4Aswflkm6g1TBlank0TTFBXC1irl4\nd6X9leIQZVoSMENvA5f4H8+pxvro0Sx4nH6wLjouA6rQZuuWFeVrrsqC8Z5n\nZcjN\r\n=Xvjy\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDZR5JpUOPl7iXzjU777LuwEQsZpmp/peCZ9yapZ1ndUQIhANw4xzCEf0W4AWpx/o9+QW7FuBXXd9YVC42MDn0GKGXe"}]},"_npmUser":{"name":"arutkowski00","email":"a_rutkowski@outlook.com"},"directories":{},"maintainers":[{"name":"arutkowski00","email":"a_rutkowski@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openapi-client-axios_4.1.0-patch.1_1636032614217_0.18442835408448022"},"_hasShrinkwrap":false}},"time":{"created":"2021-11-04T13:30:14.158Z","4.1.0-patch.1":"2021-11-04T13:30:14.351Z","modified":"2022-04-04T15:41:09.605Z"},"maintainers":[{"name":"arutkowski00","email":"a_rutkowski@outlook.com"}],"description":"JavaScript client library for consuming OpenAPI-enabled APIs with axios. Types included.","homepage":"https://github.com/anttiviljami/openapi-client-axios","keywords":["openapi","swagger","client","axios","frontend","browser","mock","typescript"],"repository":{"type":"git","url":"git+https://github.com/anttiviljami/openapi-client-axios.git"},"author":{"name":"Viljami Kuosmanen","email":"viljami@viljami.io"},"bugs":{"url":"https://github.com/anttiviljami/openapi-client-axios/issues"},"license":"MIT","readme":"<h1 align=\"center\"><img alt=\"openapi-client-axios\" src=\"./header.png\" style=\"max-width:50rem\"></h1>\n\n[![CI](https://github.com/anttiviljami/openapi-client-axios/workflows/CI/badge.svg)](https://github.com/anttiviljami/openapi-client-axios/actions?query=workflow%3ACI)\n[![Dependencies](https://david-dm.org/anttiviljami/openapi-client-axios.svg)](https://david-dm.org/anttiviljami/openapi-client-axios)\n[![npm version](https://img.shields.io/npm/v/openapi-client-axios.svg)](https://www.npmjs.com/package/openapi-client-axios)\n[![npm downloads](https://img.shields.io/npm/dw/openapi-client-axios)](https://www.npmjs.com/package/openapi-client-axios)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/openapi-client-axios?label=gzip%20bundle)](https://www.npmjs.com/package/openapi-client-axios)\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/anttiviljami/openapi-client-axios.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/anttiviljami/openapi-client-axios/alerts/)\n[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/anttiviljami/openapi-client-axios.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/anttiviljami/openapi-client-axios/context:javascript)\n[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/anttiviljami/openapi-client-axios/blob/master/LICENSE)\n[![Sponsored](https://img.shields.io/badge/chilicorn-sponsored-brightgreen.svg?logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAPCAMAAADjyg5GAAABqlBMVEUAAAAzmTM3pEn%2FSTGhVSY4ZD43STdOXk5lSGAyhz41iz8xkz2HUCWFFhTFFRUzZDvbIB00Zzoyfj9zlHY0ZzmMfY0ydT0zjj92l3qjeR3dNSkoZp4ykEAzjT8ylUBlgj0yiT0ymECkwKjWqAyjuqcghpUykD%2BUQCKoQyAHb%2BgylkAyl0EynkEzmkA0mUA3mj86oUg7oUo8n0k%2FS%2Bw%2Fo0xBnE5BpU9Br0ZKo1ZLmFZOjEhesGljuzllqW50tH14aS14qm17mX9%2Bx4GAgUCEx02JySqOvpSXvI%2BYvp2orqmpzeGrQh%2Bsr6yssa2ttK6v0bKxMBy01bm4zLu5yry7yb29x77BzMPCxsLEzMXFxsXGx8fI3PLJ08vKysrKy8rL2s3MzczOH8LR0dHW19bX19fZ2dna2trc3Nzd3d3d3t3f39%2FgtZTg4ODi4uLj4%2BPlGxLl5eXm5ubnRzPn5%2Bfo6Ojp6enqfmzq6urr6%2Bvt7e3t7u3uDwvugwbu7u7v6Obv8fDz8%2FP09PT2igP29vb4%2BPj6y376%2Bu%2F7%2Bfv9%2Ff39%2Fv3%2BkAH%2FAwf%2FtwD%2F9wCyh1KfAAAAKXRSTlMABQ4VGykqLjVCTVNgdXuHj5Kaq62vt77ExNPX2%2Bju8vX6%2Bvr7%2FP7%2B%2FiiUMfUAAADTSURBVAjXBcFRTsIwHAfgX%2FtvOyjdYDUsRkFjTIwkPvjiOTyX9%2FAIJt7BF570BopEdHOOstHS%2BX0s439RGwnfuB5gSFOZAgDqjQOBivtGkCc7j%2B2e8XNzefWSu%2BsZUD1QfoTq0y6mZsUSvIkRoGYnHu6Yc63pDCjiSNE2kYLdCUAWVmK4zsxzO%2BQQFxNs5b479NHXopkbWX9U3PAwWAVSY%2FpZf1udQ7rfUpQ1CzurDPpwo16Ff2cMWjuFHX9qCV0Y0Ok4Jvh63IABUNnktl%2B6sgP%2BARIxSrT%2FMhLlAAAAAElFTkSuQmCC)](http://spiceprogram.org/oss-sponsorship)\n[![Buy me a coffee](https://img.shields.io/badge/donate-buy%20me%20a%20coffee-orange)](https://buymeacoff.ee/anttiviljami)\n\n<p align=\"center\">JavaScript client library for consuming OpenAPI-enabled APIs with <a href=\"https://github.com/axios/axios\" target=\"_blank\">axios</a>. Types included.</p>\n\n## Features\n\n- [x] Create API clients from [OpenAPI v3 definitions](https://github.com/OAI/OpenAPI-Specification)\n- [x] Easy to use API to call API operations using JavaScript methods\n  - `client.getPet(1)`\n  - `client.searchPets()`\n  - `client.searchPets({ ids: [1, 2, 3] })`\n  - `client.updatePet(1, payload)`\n- [x] Built on top of the robust [axios](https://github.com/axios/axios) JavaScript library\n- [x] Isomorphic, works both in browser and Node.js\n- [x] Generate TypeScript definitions (.d.ts) for your APIs with full IntelliSense support\n\n## Documentation\n\nSee [DOCS.md](https://github.com/anttiviljami/openapi-client-axios/blob/master/DOCS.md)\n\n## Quick Start\n\n```\nnpm install --save axios openapi-client-axios\n```\n\n```\nyarn add axios openapi-client-axios\n```\n\nWith promises / CommonJS syntax:\n\n```javascript\nconst OpenAPIClientAxios = require('openapi-client-axios').default;\n\nconst api = new OpenAPIClientAxios({ definition: 'https://example.com/api/openapi.json' });\napi.init()\n  .then(client => client.getPetById(1))\n  .then(res => console.log('Here is pet id:1 from the api', res.data));\n```\n\nWith async-await / ES6 syntax:\n\n```javascript\nimport OpenAPIClientAxios from 'openapi-client-axios';\n\nconst api = new OpenAPIClientAxios({ definition: 'https://example.com/api/openapi.json' });\napi.init();\n\nasync function createPet() {\n  const client = await api.getClient();\n  const res = await client.createPet(null, { name: 'Garfield' });\n  console.log('Pet created', res.data);\n}\n```\n\n## Client\n\nOpenAPI Client Axios uses [operationIds](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#operation-object)\nin OpenAPIv3 definitions to call API operations.\n\nAfter initializing `OpenAPIClientAxios`, an axios client instance extended with OpenAPI capabilities is exposed.\n\nExample:\n```javascript\nconst api = new OpenAPIClientAxios({ definition: 'https://example.com/api/openapi.json' });\napi.init().then((client) => {\n  client.updatePet(1, { age: 12 });\n});\n```\n\n`client` is an [axios instance](https://github.com/axios/axios#creating-an-instance) initialized with\nbaseURL from OpenAPI definitions and extended with extra operation methods for calling API operations.\n\nIt also has a reference to OpenAPIClientAxios at `client.api`\n\n## Operation methods\n\nOpenAPIClientAxios operation methods take 3 arguments:\n\n```javascript\nclient.operationId(parameters?, data?, config?)\n```\n\n### Parameters\n\nThe first argument is used to pass parameters available for the operation.\n\n```javascript\n// GET /pets/{petId}\nclient.getPet({ petId: 1 })\n```\n\nFor syntactic sugar purposes, you can also specify a single implicit parameter value, in which case OpenAPIClientAxios\nwill look for the first required parameter for the operation. Usually this is will be a path parameter.\n\n```javascript\n// GET /pets/{petId} - getPet\nclient.getPet(1)\n```\n\nAlternatively, you can explicitly specify parameters in array form. This method allows you to set custom parameters not defined\nin the OpenAPI spec.\n\n```javascript\n// GET /pets?search=Garfield - searchPets\nclient.searchPets([{ name: 'search', value: 'Garfield', in: 'query' }])\n```\n\nThe type of the parameters can be any of:\n- query\n- header\n- path\n- cookie\n\n### Data\n\nThe second argument is used to pass the requestPayload\n\n```javascript\n// PUT /pets/1 - updatePet\nclient.updatePet(1, { name: 'Odie' })\n```\n\nMore complex payloads, such as Node.js streams or FormData supported by Axios can be used.\n\nThe first argument can be set to null if there are no parameters required for the operation.\n\n```javascript\n// POST /pets - createPet\nclient.updatePet(null, { name: 'Garfield' })\n```\n\n### Config object\n\nThe last argument is the config object.\n\nThe config object is an [`AxiosRequestConfig`](https://github.com/axios/axios#request-config) object. You can use it to\noverride axios request config parameters, such as `headers`, `timeout`, `withCredentials` and many more.\n\n```javascript\n// POST /user - createUser\nclient.createUser(null, { user: 'admin', pass: '123' }, { headers: { 'x-api-key': 'secret' } });\n```\n\n## Paths Dictionary\n\nOpenAPI Client Axios also allows calling API operations via their path and HTTP\nmethod, using the paths dictionary.\n\nExample:\n\n```javascript\nclient.paths['/pets'].get(); // GET /pets, same as calling client.getPets()\nclient.paths['/pets'].post(); // POST /pets\nclient.paths['/pets/{petId}'].put(1); // PUT /pets/1\nclient.paths['/pets/{petId}/owner/{ownerId}'].get({ petId: 1, ownerId: 2 }) ; // GET /pets/1/owner/2\n```\n\nThis allows calling operation methods without using their operationIds, which\nmay be sometimes preferred.\n\n## Generating type files (.d.ts)\n\n![TypeScript IntelliSense](typegen/intellisense.gif)\n\n`openapi-client-axios` comes with a tool called `typegen` to generate typescript type files (.d.ts) for\nOpenAPIClient instances using an OpenAPI definition file.\n\n```\n$ npm install -g openapi-client-axios-typegen\n```\n\n```\nUsage: typegen [file]\n\nOptions:\n  --help     Show help                                                 [boolean]\n  --version  Show version number                                       [boolean]\n\nExamples:\n  typegen ./openapi.yml > client.d.ts  - generate a type definition file\n```\n\nThe output of `typegen` exports a type called `Client`, which can be used for instances created with `OpenAPIClientAxios`.\n\nBoth the `api.getClient()` and `api.init()` methods support passing in a Client type.\n\n```typescript\nimport { Client as PetStoreClient } from './client.d.ts';\n\nconst client = await api.init<PetStoreClient>();\nconst client = await api.getClient<PetStoreClient>();\n```\n\n`typegen` supports using both local and remote URLs for OpenAPI definition files.\n\n```\n$ typegen ./petstore.yaml\n$ typegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml\n```\n\n## Contributing\n\nOpenAPI Client Axios is Free and Open Source Software. Issues and pull requests are more than welcome!\n\n[<img alt=\"The Chilicorn\" src=\"http://spiceprogram.org/assets/img/chilicorn_sticker.svg\" width=\"250\" height=\"250\">](https://spiceprogram.org/oss-sponsorship)\n\n","readmeFilename":"README.md"}