{"id":15286090,"url":"https://github.com/flowup/api-client-generator","last_synced_at":"2025-04-06T13:11:45.403Z","repository":{"id":26720181,"uuid":"105051980","full_name":"flowup/api-client-generator","owner":"flowup","description":"Angular REST API client generator from Swagger YAML or JSON file with camel case settigs","archived":false,"fork":false,"pushed_at":"2024-06-19T11:14:30.000Z","size":2825,"stargazers_count":115,"open_issues_count":30,"forks_count":21,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-30T11:11:11.218Z","etag":null,"topics":["angular","angular-http","angular9","api","generator","httpclient","json","models","ngx","rest","rest-api","scaffolding","swagger","swagger-yaml","typescript","yaml"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/flowup.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2017-09-27T18:06:29.000Z","updated_at":"2024-08-27T14:31:05.000Z","dependencies_parsed_at":"2024-09-30T15:10:57.913Z","dependency_job_id":"25eca3e0-f99b-41de-ad87-127d3cc19e80","html_url":"https://github.com/flowup/api-client-generator","commit_stats":{"total_commits":407,"total_committers":12,"mean_commits":"33.916666666666664","dds":0.08108108108108103,"last_synced_commit":"178d06054f062dfbd0bf61f8e7fe5570530e3e05"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowup%2Fapi-client-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowup%2Fapi-client-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowup%2Fapi-client-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowup%2Fapi-client-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flowup","download_url":"https://codeload.github.com/flowup/api-client-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247485290,"owners_count":20946398,"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":["angular","angular-http","angular9","api","generator","httpclient","json","models","ngx","rest","rest-api","scaffolding","swagger","swagger-yaml","typescript","yaml"],"created_at":"2024-09-30T15:10:25.352Z","updated_at":"2025-04-06T13:11:45.378Z","avatar_url":"https://github.com/flowup.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/api-client-generator.svg)](https://www.npmjs.com/package/api-client-generator)\n[![license](https://user-images.githubusercontent.com/7274335/42030802-46abac1e-7ad4-11e8-971e-e8b549a922d0.png)](https://www.npmjs.com/package/api-client-generator)\n[![npm](https://img.shields.io/npm/dm/api-client-generator.svg)](https://www.npmjs.com/package/api-client-generator)\n\n[![Caretaker](https://user-images.githubusercontent.com/7274335/42030799-466edd34-7ad4-11e8-9a47-37f12ac8d153.png)](https://github.com/vmasek)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![Conventional Commits](https://user-images.githubusercontent.com/7274335/42030800-4690ea1e-7ad4-11e8-9e37-6fe8b2cb3801.png)](https://conventionalcommits.org)\n[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/api-client-gen)\n\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/flowup/api-client-generator.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/flowup/api-client-generator/alerts/)\n[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/flowup/api-client-generator.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/flowup/api-client-generator/context:javascript)\n\n[![GitHub stars](https://img.shields.io/github/stars/flowup/api-client-generator.svg?style=social\u0026label=Star)](https://github.com/flowup/api-client-generator)\n[![tweet](https://user-images.githubusercontent.com/7274335/42030803-46cd231c-7ad4-11e8-992c-2a5b933383c9.png)](https://twitter.com/intent/tweet?text=Tool%20that%20lets%20you%20generate%20API%20client%20from%20a%20swagger%20file\u0026hashtags=angular,swagger,api,angular5\u0026url=https://github.com/flowup/api-client-generator)\n\n# API client generator\n\nAngular REST API client generator from Swagger YAML or JSON file with camel case settings\n\n![Logo](https://raw.githubusercontent.com/flowup/api-client-generator/master/api-client-generator-logo.png)\n\n# Description\n\nThis package generates an Angular TypeScript class from a Swagger v2.0 specification file. The code is generated using combination of Handlebars templates and in-code template strings.\n\nThe generated service class uses new [HttpClient](https://angular.io/guide/http) module of Angular (introduced in version 4.3).\n\n### Motivation\n\nThis tool provides an easy and sustainable solution for making the classic REST API feel like you wish it has felt in TypeScript.\n\nIt starts by having the same data models at front-end and back-end, then continues with API client interface in form of service build on Angular HTTP client. Everything is typed and described in the way developer don't even need to study the API endpoints.\n\nAll you need to set it up is an up to date swagger file and Angular project.\n\n##### How is this relevant for you?\n\nA lot of developers is struggling with how to properly use the REST API in their apps. In Angular, we have a great opportunity which is HTTP Client supporting types. It is a great experience when you can work on a project where your models and data service are pre-generated, and you can focus on state management, UI and business logic.\n\n# Compatibility\n\nThis generator focuses on supporting latest Angular/RxJS versions.\n\n- **Angular 9+**\n- **RxJS 6+** (Observable imports)\n\n  - in case of rxjs \u003c6 please update or rewrite the rxjs imports to match the older version\n\n## Older versions\n\nIf you need compatibility for Angular 7 and less, It might require some additional steps. In case of problems try editing necessary imports manually or downgrading to older generator versions (4.6.0 and bellow), although it is not recommended as patches and fixes might not be present in older versions.\n\nSee the [Changelog](https://github.com/flowup/api-client-generator/blob/master/CHANGELOG.md) to keep up with the features and changes.\n\n# Usage\n\nThis command will generate API client described in the swagger.json file to the `./output` folder.\n\n`npx api-client-generator -s ./path/to/swagger.json -o ./output`\n\nThis command will do the same, but it will split **all of the tags to separate API services** and models folder will be shared. All will be generated to specified path and that is `./src/api` folder.\n\n`npx api-client-generator -t all -s ./path/to/swagger.yaml -o ./src/api`\n\n### Script in Package JSON\n\n`npm install api-client-generator --save-dev`\n\n- for quick usage create run script in your `package.json` scripts.\n\n```\n\"scripts\": {\n  \"generate-api-client\": \"api-client-generator -s ./swagger.yaml -o ./output-folder\"\n},\n```\n\n**Recommended:**\n\n- use a \"tag\" (`-t all`) option to generate all (or list of specific) services separately\n\n```\n\"scripts\": {\n  \"generate-api-client\": \"api-client-generator -s ./swagger.yaml -o ./output-folder -t all\"\n},\n```\n\n- then just run\n\n`npm run generate-api-client`\n\nIn case you want to use swagger fie from a remote source, you can use curl (or simillar tool to fetch the file) and run the generator, as shown in the examples bellow.\n\n```bash\ncurl https://raw.githubusercontent.com/flowup/api-client-generator/master/tests/custom/swagger.yaml -o swagger.yaml \u0026\u0026npm run generate-api-client\n```\n\nOr directly run via `npx`\n\n```bash\ncurl https://raw.githubusercontent.com/flowup/api-client-generator/master/tests/custom/swagger.yaml -o swagger.yaml \u0026\u0026npx api-client-generator -t all -s ./path/to/swagger.yaml -o ./src/api\n```\n\nThis will download and save the swagger.yaml, and later on use the file to generate API client.\n\n**NOTE**: if you want to skip the installation for project, you can use `npx` but be careful as you'll be using the latest version every time you run the script (We use [SEMVER](https://semver.org/) so it is safer to update over the time).\n\n# Options\n\n| Option                 | Description                                                                                  |\n| ---------------------- | -------------------------------------------------------------------------------------------- |\n| `-h`/`--help`          | print help and exit                                                                          |\n| `-s`/`--source`        | path to the swagger file (YAML or JSON)                                                      |\n| `-o`/`--output`        | path where the generated files should be emitted                                             |\n| `-C`/`--commit`        | `git commit` generated changes \\*                                                            |\n| `-v`/`--verbose`       | supply stack traces with outputted error messages                                            |\n| `-t`/`--splitPathTags` | generate services to separate modules                                                        |\n|                        | specify what particular tags should be generated. Use `,` as the separator for multiple tags |\n|                        | use `all` to emit all as a service per tag                                                   |\n| `-m`/`--skipModule`    | skip creating the index file with module export                                              |\n| `-g`/`--skipGuards`    | skip creating type guards and guarded service                                                |\n\n\u003csmall\u003e\\* The author of the commit will be `api-client-generator \u003capi-client-generator@flowup.cz\u003e`.\nIf there are any staged changes in your repository, the generator will halt pre-generation with an error to prevent including your changes in the automatic commit.\\*\u003c/small\u003e\n\n# How to use generated client\n\n1. import the `APIClientModule` in your `app.module.ts` (main module)\n\n- domain and configuration should be passed to module imports using `.forRoot` method\n- options and domain are optional\n- when a domain is not passed, host property form swagger file is used as a default\n  - if host property is not defined `window.href` with a current port is used instead\n\n```typescript\n@NgModule({\n  imports: [\n    /* Default configuration and all of it's properties is optional */\n    APIClientModule.forRoot({\n      domain: 'https://api.url', // or use value defined in environment `environment.apiUrl`\n      httpOptions: {\n        headers: {\n          myCustomHeader:\n            'this will appear in every request as one of the headers',\n        },\n        params: { someParam: 'customParam' },\n      },\n    }),\n    /* ... other imports */\n    HttpClientModule, // \u003c\u003c= this is very important import\n    // API client relies on HttpClient module and will throw and provider error if not there\n  ],\n  /* ... other stuff */\n})\nexport class AppModule {}\n```\n\n2. use `APIClient` service in your components/services/...\n\n```typescript\n@Component({\n  selector: 'my-component',\n  templateUrl: `\n    \u003cdiv *ngFor=\"let user of users\"\u003e\n      \u003cp\u003eUser name: {{user.name}}\u003c/p\u003e\n    \u003c/div\u003e\n  `,\n})\nexport class MyComponent {\n  users: User[] = [];\n\n  constructor(private readonly api: APIClient) {\n    this.api.getUsers().subscribe(users =\u003e (this.users = users));\n  }\n}\n```\n\n# Generated structure\n\n- if you are interested in how will the generated client with models look like, take a look in an `example/` folder\n\n```\noutput\n ├─ guards\n │   └─ index.ts\n ├─ models\n │   ├─ some.enum.ts\n │   ├─ some.model.ts\n │   │  ...\n │   ├─ another.model.ts\n │   └─ index.ts\n ├─ api-client.interface.ts\n ├─ api-client.service.ts\n └─ index.ts\n```\n\n# Common problems\n\n### HttpClient not provided\n\nThis or very similar error means that you forgot to import `HttpClientModule` in your root module\n\n```\nStaticInjectorError(AppModule)[APIClient -\u003e HttpClient]:\n  StaticInjectorError(Platform: core)[APIClient -\u003e HttpClient]:\n    NullInjectorError: No provider for HttpClient!\n```\n\n**Fix:**\n\n- add `HttpClientModule` to your root module (see NgModule imports in [usage](https://github.com/flowup/api-client-generator#how-to-use-generated-client))\n\n### Numeric Enums keys generated as plane number\n\nIf some of your numeric enums look like this, the problem might be that in the swagger file you are not describing the keys properly.\n\n```\nexport enum MyEnum {\n  0 = 0,\n  1 = 1,\n  2 = 2,\n}\n```\n\n**Fix**\nWe currently support two options:\n\n- formatting description into an array of `['1 Foo', '2 Bar']`\n- using `'x-enumNames'` custom property that should be in format `['Foo', 'Bar']`\n\n# Problem reporting and contributions\n\nPlease report any problems you have any issues you find, so they can be resolved.\nIf the generator terminates with an error message, please re-run it with the `-v` flag and post the outputted stack trace.\n\nFeel free to discuss desired improvements or functionality in issues. Afterwards, the pull requests are very welcome.\n\n## Development\n\nIf you are interested in contributing please follow these steps:\n\n1. [Create the issue](https://github.com/flowup/api-client-generator/issues/new) and discuss the problem\n2. Fork the repo\n3. Run `npm run dev:install` instead of `npm install` to install all (even test) dependencies\n4. Add your feature/fix\n   - follow the code style\n   - check for the lint errors\n   - in case of questions visit [gitter](https://gitter.im/api-client-gen) to chat with contributors\n5. Run the tests `npm run tests`\n6. Open the PR to [upstream master](https://github.com/flowup/api-client-generator/compare)\n   - mention the issue/bug/feature it solves/closes\n\n---\n\n.\n\n.\n\n.\n\n.\n\n\u003csmall\u003e_Inspired by [swagger-js-codegen](https://github.com/wcandillon/swagger-js-codegen)_\u003c/small\u003e\n\n\u003csmall\u003e_Generator based on [angular4-swagger-client-generator](https://github.com/lotjomik/angular4-swagger-client-generator)_\u003c/small\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowup%2Fapi-client-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflowup%2Fapi-client-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowup%2Fapi-client-generator/lists"}