Gathering detailed insights and metrics for swagger-typescript
Gathering detailed insights and metrics for swagger-typescript
Gathering detailed insights and metrics for swagger-typescript
Gathering detailed insights and metrics for swagger-typescript
An auto typescript/javascript code generator from swagger.
npm install swagger-typescript
Typescript
Module System
Node Version
NPM Version
59.4
Supply Chain
96.2
Quality
75.7
Maintenance
100
Vulnerability
98.2
License
Support Postman
Updated on Aug 12, 2022
Support multi git branches (git flow)
Updated on Jul 09, 2022
Generate react hooks for apis
Updated on Oct 11, 2021
Generate mock data
Updated on Mar 05, 2021
swagger v2 supported
Updated on Jan 27, 2021
Handle FromData types
Updated on Jan 27, 2021
TypeScript (95.57%)
JavaScript (4.3%)
Shell (0.14%)
Total Downloads
105,406
Last Day
115
Last Week
611
Last Month
3,147
Last Year
45,608
MIT License
78 Stars
411 Commits
22 Forks
3 Watchers
1 Branches
10 Contributors
Updated on Mar 06, 2025
Minified
Minified + Gzipped
Latest Version
6.9.0
Package Id
swagger-typescript@6.9.0
Unpacked Size
286.52 kB
Size
59.64 kB
File Count
144
NPM Version
9.8.1
Node Version
18.18.0
Published on
Nov 30, 2024
Cumulative downloads
Total Downloads
Last Day
101.8%
115
Compared to previous day
Last Week
13.6%
611
Compared to previous week
Last Month
-15.5%
3,147
Compared to previous month
Last Year
90.3%
45,608
Compared to previous year
3
22
:star::star::star: If you would like to contribute, please refer to To do list and a list of open tasks.:star::star::star:
Support OpenApi v3, swagger v2 and postman collection
An auto typescript/javascript/kotlin code generator from APIs doc. Each endpoint will be created as a function, full type base. Supported
For Example: Get method of '/Account' path will be this code in services.ts
1import { getAccount } from "./services"; 2 3const response = await getAccount({ id: 1234 });
$ yarn add swagger-typescript prettier -D && yarn add axios
Before running, add your config to swagger.config.json
1{ 2 "url": "http://example.com/api/swagger.json", 3 "dir": "./services", 4 "prefix": "/api" 5}
yarn swag-ts
baseConfig
1const baseConfig: AxiosRequestConfig = { 2 baseURL: "", // <--- Add your base url 3 //other static configs 4};
Now you can use APIs, So for advanced config read below.
For Example:
1{ 2 "$schema": "https://raw.githubusercontent.com/hosseinmd/swagger-typescript/master/schema/v6.json", 3 "url": "http://example.com/api/swagger.json", 4 "dir": "./services", 5 "prettierPath": ".prettierrc", 6 "language": "typescript" 7}
[Key ] | [default ] | Comment |
---|---|---|
url | Required | swagger or postman collection Address. can be online or local (json/yaml) (specific branch) |
dir | Required | Address of output |
language | typescript | export to "javascript", "typescript" or "kotlin" |
methodName | {method}{path} | Supported mixed of "{method}{path}{operationId}". for Example: 'service{method}{path}' |
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 |
ignore | Optional | Ignore headers from type for Example: "ignore": { "headerParams": ["terminalId"]} |
mock | false | For generate response mocks |
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 |
reactHooks | false | For generate react hooks of all APIs (using react-query under the hood) |
useQuery | [] | List of apis which is get but developed with post methods (Is useful for rest apis) for Example: ["postTicketsGetall"] (Needed to enable reactHooks ) |
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 |
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 |
kotlinPackage | Required (Only kotlin) | package name of source dir |
generateEnumAsType | false | |
includes | [] | A list of regex patterns that specify which APIs to include based on matching method names |
excludes | [] | A list of regex patterns that specify which APIs to exclude based on matching method names |
enum ReferralStatus {Successed="Successed","Error"="Error"}
type ReferralStatus="Successed" | "Error"; // generateEnumAsType = true
[Key ] | [default ] | Comment |
---|---|---|
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 |
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 |
config | "./swagger.config.json" | A path for config file location - yarn swag-ts --config=./config path is related for "swagger.config.json" file in config folder - yarn swag-ts --config=./config/myswagger.json you could change config file name - yarn swag-ts --config=/user/hosseinmd/desktop/config/swagger.config.json you could add absolute path |
The 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.
getAxiosInstance
getAxiosInstance used for create an instance of axios request you can customize that for what you needed
baseConfig
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.
1const { generate } = require("swagger-typescript"); 2 3generate(config); 4// or 5generate(); // will be use ./swagger.config.json
In 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.
For Doing this you need to add this to your swagger.config.json
"keepJson": true,
This code will keep previous JSON for updating partially.
Run $ yarn swag-ts
with your base backend, for example develop branch
Others need to pull this changes
Now you can update Tag1 and Tag2 $ yarn swag-ts Tag1 Tag2
.
if you have multiple gateway in your project you could handle it by add array of config in swagger.config.json
1[ 2 { 3 "$schema": "https://raw.githubusercontent.com/hosseinmd/swagger-typescript/master/schema/v6.json", 4 "url": "http://example1.com/api/swagger.json", 5 "dir": "./service1", 6 "prettierPath": ".prettierrc", 7 "language": "typescript" 8 }, 9 { 10 "$schema": "https://raw.githubusercontent.com/hosseinmd/swagger-typescript/master/schema/v6.json", 11 "url": "http://example2.com/api/swagger.json", 12 "dir": "./service2", 13 "prettierPath": ".prettierrc", 14 "language": "typescript" 15 } 16]
if 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).
For Example:
1{ 2 "url": [ 3 { 4 "branch": "master", 5 "url": "http:/example.com/api/swagger.json" 6 }, 7 { 8 "branch": "develop", 9 "url": "http://stage.example.com/api/swagger.json" 10 } 11 ] 12}
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
why-you-should-use-swagger-typescript-for-generate-apis-code
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
24 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-04-21
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More