{"id":25379309,"url":"https://github.com/michaelhilus/openapi-typescript-client-api-generator","last_synced_at":"2025-10-30T09:30:32.350Z","repository":{"id":57138225,"uuid":"195190834","full_name":"MichaelHilus/openapi-typescript-client-api-generator","owner":"MichaelHilus","description":"A generator that reads swagger / open api 3 json configs and generates typescript client services with axios","archived":false,"fork":false,"pushed_at":"2019-09-27T16:35:56.000Z","size":26,"stargazers_count":10,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T14:47:28.491Z","etag":null,"topics":["axios","open-api-v3","swagger","typescript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MichaelHilus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-04T07:27:16.000Z","updated_at":"2024-10-11T14:26:54.000Z","dependencies_parsed_at":"2022-08-25T10:10:34.687Z","dependency_job_id":null,"html_url":"https://github.com/MichaelHilus/openapi-typescript-client-api-generator","commit_stats":null,"previous_names":["michaelhilus/openapi-typescript-client-api-generator","progresso-group/openapi-typescript-client-api-generator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelHilus%2Fopenapi-typescript-client-api-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelHilus%2Fopenapi-typescript-client-api-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelHilus%2Fopenapi-typescript-client-api-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelHilus%2Fopenapi-typescript-client-api-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MichaelHilus","download_url":"https://codeload.github.com/MichaelHilus/openapi-typescript-client-api-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238947032,"owners_count":19556994,"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":["axios","open-api-v3","swagger","typescript"],"created_at":"2025-02-15T05:19:41.193Z","updated_at":"2025-10-30T09:30:32.019Z","avatar_url":"https://github.com/MichaelHilus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openapi-typescript-client-api-generator\nA generator that reads swagger / open api 3 json configs and generates typescript client services with axios.\n\nHint: implemented with specific use case in mind.\n\n[![npm version](https://badge.fury.io/js/%40progresso%2Fopenapi-typescript-client-api-generator.svg)](https://badge.fury.io/js/%40progresso%2Fopenapi-typescript-client-api-generator)\n\n## Example\n\nYour open-api 3 json config file:\n```json\n{\n  \"openapi\": \"3.0.1\",\n  \"info\": {\n    \"title\": \"Awesome project API\",\n    \"description\": \"The API that is just awesome.\",\n    \"version\": \"1.3.8\"\n  },\n  \"tags\" : [ { \"name\" : \"users\" } ],\n  ...\n  \"paths\": {\n    \"/users\": {\n      \"get\": {\n        \"tags\": [ \"users\" ],\n        \"operationId\": \"getAllUsers\",\n        \"description\": \"Gets all users. Can optionally be filtered by group id.\",\n        \"parameters\": [ {\n          \"name\": \"groupId\",\n          \"in\": \"query\",\n          \"description\": \"The group of the users to retrieve.\",\n          \"required\": false,\n          \"schema\": {\n            \"type\": \"integer\",\n            \"format\": \"int32\"\n          }\n        } ],\n        \"responses\": {\n          \"default\": {\n            \"description\": \"The users.\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {\n                  \"type\": \"array\",\n                  \"items\": {\n                    \"$ref\" : \"#/components/schemas/User\"\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    },\n    \"/users/{userId}\": {\n      \"get\": {\n        \"tags\": [ \"users\" ],\n        \"operationId\": \"getUserById\",\n        \"description\": \"Retrieve a user by id.\",\n        \"parameters\": [ {\n          \"name\": \"userId\",\n          \"in\": \"path\",\n          \"description\": \"The id of the user to retrieve.\",\n          \"required\": true,\n          \"schema\": {\n            \"type\": \"integer\",\n            \"format\": \"int32\"\n          }\n        } ],\n        \"responses\": {\n          \"default\": {\n            \"description\": \"The user.\",\n            \"content\": {\n              \"application/json\": {\n                \"schema\": {\n                  \"$ref\" : \"#/components/schemas/User\"\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  },\n  \"components\": {\n    \"schemas\": {\n      \"User\": {\n        \"description\": \"The user.\",\n        \"type\": \"object\",\n        \"properties\": {\n          \"id\": {\n            \"type\": \"integer\",\n            \"format\": \"int32\",\n            \"description\": \"The id of the user.\"\n          },\n          \"name\": {\n            \"type\": \"string\",\n            \"description\": \"The name of the user.\"\n          },\n          \"groupId\": {\n            \"type\": \"integer\",\n            \"format\": \"int32\",\n            \"description\": \"The group id of the user.\"\n          }\n        }\n      }\n    }\n  }\n}\n```\n\nGenerated model ( `user.ts` )\n```typescript\n/**\n * Awesome project API 1.3.8 (OpenAPI: 3.0.1)\n * The API that is just awesome.\n *\n * NOTE: This class is auto generated by openapi-typescript-client-api-generator.\n * Do not edit the file manually.\n */\n\nexport class User {\n\n    /**\n     * Creates a ListColumn.\n     *\n     * @param {number} id The id of the user.\n     * @param {string} name The name of the user.\n     * @param {number} groupId The group id of the user.\n     */\n    constructor(id: number, name: string, groupId: number) {\n        this.id = id;\n        this.name = name;\n        this.groupId = groupId;\n    }\n\n    /**\n     * The id of the user.\n     */\n    public id: number;\n\n    /**\n     * The name of the user.\n     */\n    public name: string;\n\n    /**\n     * The group id of the user.\n     */\n    public group id: number;\n}\n```\n\nGenerated service ( `usersService.ts` )\n```typescript\n/**\n * Awesome project API 1.3.8 (OpenAPI: 3.0.1)\n * The API that is just awesome.\n *\n * NOTE: This class is auto generated by openapi-typescript-client-api-generator.\n * Do not edit the file manually.\n */\n\nimport axios from \"axios\";\n\nimport { ServiceBase } from \"../../services/serviceBase\";\nimport { IUsersService } from \"./usersService.interface\";\n\nimport { User } from \"../models/user\";\n\nexport class UsersService extends ServiceBase implements IUsersService {\n    /**\n     * Gets all users. Can optionally be filtered by group id.\n     *\n     * @param {number} [groupId] The group of the users to retrieve.\n     */\n    public async getAllUsers(groupId?: number): Promise\u003cUser[]\u003e {\n        const config = this.getAxiosConfiguration();\n\n        const queryList: string[] = [];\n        if (groupId !== undefined) {\n            queryList.push(`groupId=${groupId}`);\n        }\n        const query = `?${queryList.join(\"\u0026\")}`;\n\n        const response = await axios.get\u003cUser[]\u003e(`/users${query}`, config);\n        return response.data;\n    }\n\n    /**\n     * Retrieve a user by id..\n     *\n     * @param {number} userId The id of the user to retrieve.\n     */\n    public async getUserById(userId?: number): Promise\u003cUser[]\u003e {\n        const config = this.getAxiosConfiguration();\n\n        const response = await axios.get\u003cUser[]\u003e(`/users/${userId}`, config);\n        return response.data;\n    }\n}\n```\n\n## Installation\n```shell\n$ yarn add @progresso/openapi-typescript-client-api-generator --dev\n```\n\n## Usage\n\n### Add an open-api 2.0 / 3.x file to your project\nAdd a swagger (open-api 2.0) or open-api 3 json config file into your project. I.e. at  \n`[project-root]/api/awesone-api.json`\n\n### Configure scripts section in package.json\nAdd a script line into your `package.json`:\n```json\n{\n  ...\n  \"scripts\": {\n    \"generate\": \"openapi-typescript-client-api-generator\"\n  }\n}\n```\n### Implement ServiceBase for request headers\nImplement a service base class called `ServiceBase` that implements the following method so you are able to pass custom headers like authentication tokens to your requests: \n```typescript\nprotected getAxiosConfiguration(): AxiosRequestConfig\n```\n\n### Run the generator\nExecute the generator with\n```shell\n$ yarn generate -c /api/awesome-api.json -sb /client/services -s /client/api/services -m /client/api/models -sm /server/modules/api/models\n```\n\n## Parameter documentation\nAll parameters are required currently. All pathes are relative to the project root.\n\n| Parameter    | Description                                                                                               | Example                 |\n|--------------|-----------------------------------------------------------------------------------------------------------|-------------------------|\n| `-c \u003cpath\u003e`  | The path to your json config file.                                                                        | `/api/awesome-api.json` |\n| `-sb \u003cpath\u003e` | The path to the directory where your `ServiceBase` class is located.                                      | `/client/services`      |\n| `-s \u003cpath\u003e`  | The path to the directory where the generated services should be saved to. Will be created if neccessary. | `/client/api/services`  |\n| `-m \u003cpath\u003e`  | The path to the directory where the generated models should be saved to. Will be created if neccessary.   | `/client/api/models`    |\n| `-sm \u003cpath\u003e` | The path to a directory that contains server side models decorated for `@nestjs/swagger` generation. Used when the config file's version is 2.0 (swagger) to augment services and models by inheritance information. Not used when config file's version is \u003e= 3.0.0 (open-api 3). | `/server/modules/api/models` |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelhilus%2Fopenapi-typescript-client-api-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelhilus%2Fopenapi-typescript-client-api-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelhilus%2Fopenapi-typescript-client-api-generator/lists"}