{"id":13469491,"url":"https://github.com/hosseinmd/swagger-typescript","last_synced_at":"2025-10-05T21:45:04.396Z","repository":{"id":43456978,"uuid":"286850336","full_name":"hosseinmd/swagger-typescript","owner":"hosseinmd","description":"An auto typescript/javascript code generator from swagger.","archived":false,"fork":false,"pushed_at":"2025-08-22T11:25:30.000Z","size":1348,"stargazers_count":83,"open_issues_count":2,"forks_count":23,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-13T18:57:56.517Z","etag":null,"topics":["api","openapi","rest","swagger","typescript"],"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/hosseinmd.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,"zenodo":null}},"created_at":"2020-08-11T21:21:02.000Z","updated_at":"2025-08-27T12:24:20.000Z","dependencies_parsed_at":"2023-01-30T03:00:26.417Z","dependency_job_id":"6a6a515a-6be4-45fc-9aaf-a6aad72ab5b9","html_url":"https://github.com/hosseinmd/swagger-typescript","commit_stats":null,"previous_names":[],"tags_count":128,"template":false,"template_full_name":null,"purl":"pkg:github/hosseinmd/swagger-typescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosseinmd%2Fswagger-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosseinmd%2Fswagger-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosseinmd%2Fswagger-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosseinmd%2Fswagger-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hosseinmd","download_url":"https://codeload.github.com/hosseinmd/swagger-typescript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosseinmd%2Fswagger-typescript/sbom","scorecard":{"id":469346,"data":{"date":"2025-08-11","repo":{"name":"github.com/hosseinmd/swagger-typescript","commit":"70f8f4398fb3164ec1ef85fde8c4f4031e83539a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.9,"checks":[{"name":"Code-Review","score":0,"reason":"Found 2/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":1,"reason":"0 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"26 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx","Warn: Project is vulnerable to: GHSA-jr5f-v2jv-69x6","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v","Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T13:24:55.163Z","repository_id":43456978,"created_at":"2025-08-19T13:24:55.163Z","updated_at":"2025-08-19T13:24:55.163Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278526240,"owners_count":26001325,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","openapi","rest","swagger","typescript"],"created_at":"2024-07-31T15:01:42.146Z","updated_at":"2025-10-05T21:45:04.342Z","avatar_url":"https://github.com/hosseinmd.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[![NPM](https://nodei.co/npm/swagger-typescript.png)](https://nodei.co/npm/swagger-typescript/)\n\n[![install size](https://packagephobia.now.sh/badge?p=swagger-typescript)](https://packagephobia.now.sh/result?p=swagger-typescript) [![dependencies](https://david-dm.org/hosseinmd/swagger-typescript.svg)](https://david-dm.org/hosseinmd/swagger-typescript.svg)\n\n:star::star::star: If you would like to contribute, please refer to [To do list](https://github.com/hosseinmd/swagger-typescript/projects/1) and a list of [open tasks](https://github.com/hosseinmd/swagger-typescript/issues?q=is%3Aopen).:star::star::star:\n\n# Swagger-Typescript: Generate ts/js code from swagger/openApi JSON\n\nSupport OpenApi v3, swagger v2 and postman collection\n\nAn auto typescript/javascript/kotlin code generator from APIs doc.\nEach endpoint will be created as a function, full type base.\nSupported\n\n- Generating a function for every apis\n- Generating all types, interfaces and enums which used in apis\n- React hooks.\n- SignalR hub.\n- Generating mock data.\n\nFor Example:\nGet method of '/Account' path will be this code in services.ts\n\n```js\nimport { getAccount } from \"./services\";\n\nconst response = await getAccount({ id: 1234 });\n```\n\n## install\n\n`$ yarn add swagger-typescript prettier -D \u0026\u0026 yarn add axios`\n\n## get start\n\nBefore running, add your config to swagger.config.json\n\n#### swagger.config.json\n\n```json\n{\n  \"url\": \"http://example.com/api/swagger.json\",\n  \"dir\": \"./services\",\n  \"prefix\": \"/api\"\n}\n```\n\n#### run\n\n```\nyarn swag-ts\n```\n\n#### config.ts\n\n[more](#config)\n\nbaseConfig\n\n```ts\nconst baseConfig: AxiosRequestConfig = {\n  baseURL: \"\", // \u003c--- Add your base url\n  //other static configs\n};\n```\n\nNow you can use APIs, So for advanced config read below.\n\n## swagger.config.json\n\nFor Example:\n\n```json\n{\n  \"$schema\": \"https://raw.githubusercontent.com/hosseinmd/swagger-typescript/master/schema/v6.json\",\n  \"url\": \"http://example.com/api/swagger.json\",\n  \"dir\": \"./services\",\n  \"prettierPath\": \".prettierrc\",\n  \"language\": \"typescript\"\n}\n```\n\n| [`Key`]              | [`default`]            | Comment                                                                                                                                                                                                                                        |\n| -------------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `url`                | Required               | swagger or postman collection Address. can be online or local (json/yaml) ([specific branch](#specific-branch))                                                                                                                                |\n| `dir`                | Required               | Address of output                                                                                                                                                                                                                              |\n| `language`           | `typescript`           | export to \"javascript\", \"typescript\" or \"kotlin\"                                                                                                                                                                                               |\n| `methodName`         | `{method}{path}`       | Supported mixed of \"{method}{path}{operationId}\". for Example: 'service{method}{path}'                                                                                                                                                         |\n| `prefix`             | Optional               | prefix value will be removed from method name For example your endpoints is like \"/api/v2/users\", If you don't want add \"/api/v2\" to method name, add it to prefix                                                                             |\n| `ignore`             | Optional               | Ignore headers from type for Example: `\"ignore\": { \"headerParams\": [\"terminalId\"]}`                                                                                                                                                            |\n| `mock`               | false                  | For generate response mocks                                                                                                                                                                                                                    |\n| `keepJson`           | false                  | This code will keep previous JSON for updating partially. change it to true then generate service for creating your first json file then you can update a tag for example `$ yarn swag-ts User` will update your user APIs which have User tag |\n| `reactHooks`         | false                  | For generate react hooks of all APIs (using react-query under the hood)                                                                                                                                                                        |\n| `useQuery`           | []                     | List of apis which is get but developed with post methods (Is useful for rest apis) for Example: [\"postTicketsGetall\"] (Needed to enable `reactHooks`)                                                                                         |\n| `useInfiniteQuery`   | []                     | List of apis which is get and could be handle infinity (Needed to enable `reactHooks`) parameter should be one of `page`, `pageNo` or `pageNumber`                                                                                             |\n| `local`              | false                  | update swagger with local swagger.json located in your dir folder. add it to your config file or run it with cli `$ yarn swag-ts --local`                                                                                                      |\n| `kotlinPackage`      | Required (Only kotlin) | package name of source dir                                                                                                                                                                                                                     |\n| `generateEnumAsType` | false                  |\n| `includes`           | []                     | A list of regex patterns that specify which APIs to include based on matching method names                                                                                                                                                     |\n| `excludes`           | []                     | A list of regex patterns that specify which APIs to exclude based on matching method names                                                                                                                                                     |\n\n- `enum ReferralStatus {Successed=\"Successed\",\"Error\"=\"Error\"} `\n- `type ReferralStatus=\"Successed\" | \"Error\"; // generateEnumAsType = true `\n\n# CLI Options\n\n| [`Key`]  | [`default`]             | Comment                                                                                                                                                                                                                                                                                                                                        |\n| -------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `local`  | false                   | update swagger with local swagger.json located in your dir folder. add it to your config file or run it with cli `$ yarn swag-ts --local`                                                                                                                                                                                                      |\n| `branch` | Current Branch          | to generate swagger for develop run `yarn swag-ts --branch=develop` or your branch name should be `develop` or a branch which created from develop                                                                                                                                                                                             |\n| `config` | \"./swagger.config.json\" | A path for config file location \u003cbr\u003e - `yarn swag-ts --config=./config` path is related for \"swagger.config.json\" file in config folder \u003cbr\u003e - `yarn swag-ts --config=./config/myswagger.json` you could change config file name \u003cbr\u003e - `yarn swag-ts --config=/user/hosseinmd/desktop/config/swagger.config.json` you could add absolute path |\n|          |\n\n## Config\n\nThe config.ts file automatically will be created after first run. You could change this file for customization. Don't change other files, if you want another config create Issue or PR.\n\n- getAxiosInstance\n\n  getAxiosInstance used for create an instance of axios request you can customize that for what you needed\n\n- baseConfig\n\n  baseConfig used for get static configs and headers. if you need some dynamic configs like add authentication to headers use `requestConfig.headers.authorization` into of `axiosInstance.interceptors.request.use` function.\n\n## Run by node\n\n```js\nconst { generate } = require(\"swagger-typescript\");\n\ngenerate(config);\n// or\ngenerate(); // will be use ./swagger.config.json\n```\n\n## Conflict\n\nIn some situation teams have parallel backend development which cause conflict when updating swagger for solving this we have partially update, you can update your service just for a few tags and keep other old services codes.\n\nFor Doing this you need to add this to your swagger.config.json\n\n```\n\"keepJson\": true,\n```\n\nThis code will keep previous JSON for updating partially.\n\nRun `$ yarn swag-ts` with your base backend, for example develop branch\n\nOthers need to pull this changes\n\nNow you can update Tag1 and Tag2 `$ yarn swag-ts Tag1 Tag2`.\n\n## Multiple Gateway\n\nif you have multiple gateway in your project you could handle it by add array of config in swagger.config.json\n\n```json\n[\n  {\n    \"$schema\": \"https://raw.githubusercontent.com/hosseinmd/swagger-typescript/master/schema/v6.json\",\n    \"url\": \"http://example1.com/api/swagger.json\",\n    \"dir\": \"./service1\",\n    \"prettierPath\": \".prettierrc\",\n    \"language\": \"typescript\"\n  },\n  {\n    \"$schema\": \"https://raw.githubusercontent.com/hosseinmd/swagger-typescript/master/schema/v6.json\",\n    \"url\": \"http://example2.com/api/swagger.json\",\n    \"dir\": \"./service2\",\n    \"prettierPath\": \".prettierrc\",\n    \"language\": \"typescript\"\n  }\n]\n```\n\n## Specific branch\n\nif you are managing project by multiple branch like gitflow, you need to update swagger based on you working branch or parent branch (for example your parent is develop if you create a branch from develop).\n\nFor Example:\n\n```json\n{\n  \"url\": [\n    {\n      \"branch\": \"master\",\n      \"url\": \"http:/example.com/api/swagger.json\"\n    },\n    {\n      \"branch\": \"develop\",\n      \"url\": \"http://stage.example.com/api/swagger.json\"\n    }\n  ]\n}\n```\n\nto generate swagger for develop run `yarn swag-ts --branch=develop` or your branch name should be `develop` or a branch which created from develop\n\n## Stories\n\n[why-you-should-use-swagger-typescript-for-generate-apis-code](https://medium.com/@hosseinm.developer/why-you-should-use-swagger-typescript-for-generate-apis-code-63eb8623fef8?source=friends_link\u0026sk=2aa0e2d30b3be158d18c1feb4e12d4a6)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhosseinmd%2Fswagger-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhosseinmd%2Fswagger-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhosseinmd%2Fswagger-typescript/lists"}