{"id":24618105,"url":"https://github.com/winkgroup/ts-swagger","last_synced_at":"2026-04-17T02:33:23.808Z","repository":{"id":65200109,"uuid":"586797257","full_name":"WINKgroup/ts-swagger","owner":"WINKgroup","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-23T15:49:33.000Z","size":101,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-28T11:46:14.601Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/WINKgroup.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":"2023-01-09T08:55:31.000Z","updated_at":"2023-01-18T10:25:13.000Z","dependencies_parsed_at":"2023-02-13T00:31:01.092Z","dependency_job_id":null,"html_url":"https://github.com/WINKgroup/ts-swagger","commit_stats":null,"previous_names":["winkgroup/ts-to-openapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WINKgroup%2Fts-swagger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WINKgroup%2Fts-swagger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WINKgroup%2Fts-swagger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WINKgroup%2Fts-swagger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WINKgroup","download_url":"https://codeload.github.com/WINKgroup/ts-swagger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244313871,"owners_count":20433011,"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":[],"created_at":"2025-01-24T23:49:47.645Z","updated_at":"2026-04-17T02:33:23.763Z","avatar_url":"https://github.com/WINKgroup.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ts-Swagger\n\nTs-Swagger is a Javascript library that converts Typescript interfaces and Express APIs into OpenAPI/Swagger JSON.\n\nTs-Swagger library scans the Typescript files of interest and converts interfaces and APIs marked with specific comments. As a result it provides a JSON composed according to the OpenAPI 3 specification. Optionally generate a file with a .json extension in the project root.\n\n## Installation\n\n```bash\nnpm i @winkgroup/ts-swagger\n```\n\n## Usage\n\nIn order to be properly used, Ts-Swagger requires a **configuration file** with the paths containing all of your interfaces/API, along with some other info such as the documentation title (apiName) and version. Other optional info is the description and list of servers.\n\nThis file **must be placed at the root** of your project folder.\n\n```JSON\n{\n    \"pathList\": [\n        \"./model/User.ts\",\n        \"./model/Cart.ts\",\n        \"./routes/api/user.js\"\n    ],\n    \"apiName\": \"\",\n    \"version\": \"\",\n    \"description\": \"\",\n    \"servers\": [\n        {\n            \"url\": \"http://localhost:3000/\",\n            \"description\": \"Staging\"\n        },\n    ]\n}\n```\n\nIn order for the library to work, you need to add a **comment** inside every interface that you want to generate Swagger for.\n```ts\n// swagger\n```\n```ts\n\n// This interface will be converted \nexport interface User {\n    // swagger\n    name: string,\n    id: number\n}\n\n// This interface won't be converted\nexport interface Cart {\n    productName: string,\n    price: number,\n    quantity: number,\n    productId: number\n}\n```\n\n\nYour **APIs** will also need a comment that specifies **which interface they're using**, otherwise the swagger for them won't be generated.\n\n```js\napp.get('/users', function(req, res) {\n    // schema: User\n    res.send(Users);\n});\n```\n\nOther optional comments are the description of the API and its response.\n\n```js\napp.get('/users', function(req, res) {\n    // schema: User\n    // description: Get all users\n    // response_description: Array of users\n    res.send(Users);\n});\n```\n\nWith the following syntax you can also add the description of status codes other than 200 and if you want with an optional comment, you can provide a reference to the Typescript interface that describes the related response.\n\n```js\napp.get('/users/:userId', function(req, res) {\n    // schema: User\n    // {404}: Not found\n    // {500}: Some server error\n    // error_schema: Error\n    res.send(User);\n});\n```\n\nThe library exposes a method called **getSwagger()** that returns the Swagger JSON. If a **filename** is provided as an argument, a new file containing the JSON will be created in the root of your project.\n\n```js\nimport { TsSwagger } from \"@winkgroup/ts-swagger\";\n\n// Configuration file path must be passed inside class constructor\nconst tsswg = new TsSwagger(\"../tsswagger.config.json\");\n\n// Returns the JSON Swagger\nconst swaggerObj = tsswg.getSwagger();\n\n// Creates the JSON Swagger file\ntsswg.getSwagger('swagger.json');\n\n```\n\n## Maintainers\n* [fairsayan](https://github.com/fairsayan)\n* [alexSp84](https://github.com/alexSp84)\n* [simonechebelnome](https://github.com/simonechebelnome)\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinkgroup%2Fts-swagger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinkgroup%2Fts-swagger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinkgroup%2Fts-swagger/lists"}