{"id":27455100,"url":"https://github.com/welovecoding/swaxios","last_synced_at":"2025-04-15T15:16:42.528Z","repository":{"id":35052380,"uuid":"183629722","full_name":"welovecoding/swaxios","owner":"welovecoding","description":"A Swagger API client generator based on axios and written in TypeScript. 🌊","archived":false,"fork":false,"pushed_at":"2025-04-01T01:33:53.000Z","size":1115,"stargazers_count":17,"open_issues_count":8,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-15T15:16:33.799Z","etag":null,"topics":["api-client","api-generator","axios","browser","cli","code-generation","generator","hacktoberfest","javascript","nodejs","rest","swagger","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/swaxios","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/welovecoding.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-26T13:03:37.000Z","updated_at":"2025-04-01T01:33:56.000Z","dependencies_parsed_at":"2023-10-04T17:54:35.230Z","dependency_job_id":"4809f647-499f-4cb9-ae8e-fe2a726aefb3","html_url":"https://github.com/welovecoding/swaxios","commit_stats":{"total_commits":389,"total_committers":7,"mean_commits":55.57142857142857,"dds":0.5681233933161953,"last_synced_commit":"6bb5b00c2161d51e79ff07f5913be5728a94ef84"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welovecoding%2Fswaxios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welovecoding%2Fswaxios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welovecoding%2Fswaxios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welovecoding%2Fswaxios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/welovecoding","download_url":"https://codeload.github.com/welovecoding/swaxios/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094934,"owners_count":21211837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","api-generator","axios","browser","cli","code-generation","generator","hacktoberfest","javascript","nodejs","rest","swagger","typescript"],"created_at":"2025-04-15T15:16:41.896Z","updated_at":"2025-04-15T15:16:42.486Z","avatar_url":"https://github.com/welovecoding.png","language":"TypeScript","readme":"![Swaxios](https://github.com/welovecoding/swaxios/raw/main/logo.png)\n\n# Swaxios\n\nA [Swagger (OpenAPI v2)][oas2] API client generator based on [axios][axios] and written in [TypeScript][ts].\n\n## Motivation\n\nThe Swaxios project automates the creation of an API client for TypeScript applications, which can be used in web browsers and Node.js environments.\n\nAt the time of writing this tool (2019-04-26), the [Swagger Codegen project][codegen] only provided separate SDK generators for browsers and Node.js (`typescript-fetch` and `typescript-node`). Unfortunately, the `typescript-fetch` generator for browsers is not compatible with all Node.js applications since the fetch API became globally available only as an [experimental feature in Node.js 18](https://nodejs.org/de/blog/announcements/v18-release-announce/#fetch-experimental) (2022-04-19).\n\nSwaxios offers an API generator that works in both environments (browsers \u0026 Node.js 16+) by utilizing the flexible [axios request library][axios]. API calls are routed through axios and can be easily customized using request interceptors.\n\n## Limitations\n\nThis library can only work with a valid [OpenAPI Version 2 specification][oas2], which must be in the form of a file or URL. It does not support [OpenAPI Version 3][oas3] specifications.\n\nIf you need a generator for Open API v3 specs, you can test `typescript-axios` from [Swagger Codegen][codegen] ([added on 2020-09-21](https://github.com/swagger-api/swagger-codegen-generators/commits/master/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAxiosClientCodegen.java)).\n\n```bash\njava -jar swagger-codegen-cli-3.0.24.jar generate -l typescript-axios -i ./swagger.json -o ./api-client\n```\n\n- [Download Swagger Codegen 3.0.24](https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.24/swagger-codegen-cli-3.0.24.jar) ([Release Notes](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.24))\n\nThere is also an npm package ([@openapitools/openapi-generator-cli](https://www.npmjs.com/package/@openapitools/openapi-generator-cli)) which exposes this generator. You can use it the following way in your [scripts](https://docs.npmjs.com/cli/using-npm/scripts):\n\n```json\n{\n  \"scripts\": {\n    \"generate\": \"openapi-generator-cli generate -i ./swagger.json -g typescript-axios -p \\\"withoutRuntimeChecks=true,withInterfaces=true\\\" -o ./api-client\"\n  }\n}\n```\n\n## Installation\n\nYou can install Swaxios globally (`npm i -g swaxios`) or add it to your [devDependencies](https://docs.npmjs.com/files/package.json#devdependencies).\n\n## Usage\n\nDisplay all CLI options:\n\n```\nswaxios --help\n```\n\nIf you pass an [OpenAPI v2 specification][oas2] (JSON or YAML) to Swaxios, then it generates a fully typed API client for you which uses axios under the hood:\n\n```bash\n# Provide a Swagger input file (JSON or YAML)\nswaxios -i ./path/to/swagger.json -o ./path/to/output/directory\nswaxios -i ./path/to/swagger.yml -o ./path/to/output/directory\n\n# Alternative: Provide a URL to a Swagger endpoint\nswaxios -i http://127.0.0.1:3000/documentation-json -o ./path/to/output/directory\n```\n\nWith the `-f` option, you can force Swaxios to overwrite existing files in the output path:\n\n```bash\nswaxios -i ./path/to/swagger.json -o ./path/to/output/directory -f\n```\n\n## Examples\n\nYou can find many examples of generated API client code in our [snapshots section](./src/test/snapshots).\n\nHere is a basic example:\n\n**`ExchangeService.ts`**\n\n```ts\n/* tslint:disable */\n\n/**\n * This file was automatically generated by \"Swaxios\".\n * It should not be modified by hand.\n */\n\nimport {AxiosInstance, AxiosRequestConfig} from 'axios';\n\nexport class ExchangeService {\n  private readonly apiClient: AxiosInstance;\n\n  constructor(apiClient: AxiosInstance) {\n    this.apiClient = apiClient;\n  }\n\n  deleteExchange = async (id: number): Promise\u003cvoid\u003e =\u003e {\n    const config: AxiosRequestConfig = {\n      method: 'delete',\n      url: `/api/v1/exchange/${id}`,\n    };\n    await this.apiClient.request(config);\n  };\n}\n```\n\nIt has been generated from the following [path](https://swagger.io/docs/specification/2-0/paths-and-operations/):\n\n**`swagger.json`**\n\n```jsonc\n{\n  // ...\n  \"paths\": {\n    \"/api/v1/exchange/{id}\": {\n      \"delete\": {\n        \"consumes\": [\"application/json\"],\n        \"operationId\": \"deleteExchange\",\n        \"parameters\": [\n          {\n            \"in\": \"path\",\n            \"name\": \"id\",\n            \"required\": true,\n            \"type\": \"number\"\n          }\n        ],\n        \"produces\": [\"application/json\"],\n        \"responses\": {\n          \"200\": {\n            \"description\": \"\"\n          }\n        }\n      }\n    }\n  }\n  // ...\n}\n```\n\n## Alternatives\n\n- [OpenAPI TypeScript](https://www.npmjs.com/package/openapi-typescript)\n\n[axios]: https://github.com/axios/axios\n[codegen]: https://github.com/swagger-api/swagger-codegen\n[oas2]: https://swagger.io/specification/v2/\n[oas3]: https://swagger.io/specification/v3/\n[ts]: https://www.typescriptlang.org/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwelovecoding%2Fswaxios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwelovecoding%2Fswaxios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwelovecoding%2Fswaxios/lists"}