{"id":29081381,"url":"https://github.com/bonukai/typescript-routes-to-openapi","last_synced_at":"2026-04-27T18:05:40.283Z","repository":{"id":42571050,"uuid":"431677063","full_name":"bonukai/typescript-routes-to-openapi","owner":"bonukai","description":"Extract REST API routes from TypeScript files and generate OpenAPI documentation and input validators","archived":false,"fork":false,"pushed_at":"2023-03-14T18:12:37.000Z","size":772,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-31T00:45:25.732Z","etag":null,"topics":["openapi","swagger"],"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/bonukai.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":"2021-11-25T01:26:50.000Z","updated_at":"2022-03-15T22:06:19.000Z","dependencies_parsed_at":"2023-02-07T11:16:14.943Z","dependency_job_id":null,"html_url":"https://github.com/bonukai/typescript-routes-to-openapi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bonukai/typescript-routes-to-openapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bonukai%2Ftypescript-routes-to-openapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bonukai%2Ftypescript-routes-to-openapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bonukai%2Ftypescript-routes-to-openapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bonukai%2Ftypescript-routes-to-openapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bonukai","download_url":"https://codeload.github.com/bonukai/typescript-routes-to-openapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bonukai%2Ftypescript-routes-to-openapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32348058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T17:12:42.749Z","status":"ssl_error","status_checked_at":"2026-04-27T17:12:41.658Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["openapi","swagger"],"created_at":"2025-06-27T19:01:54.055Z","updated_at":"2026-04-27T18:05:40.264Z","avatar_url":"https://github.com/bonukai.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typescript-routes-to-openapi \u0026middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/bonukai/typescript-routes-to-openapi/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/typescript-routes-to-openapi.svg?style=flat)](https://www.npmjs.com/package/typescript-routes-to-openapi)\n\nGenerate [OpenApi](https://swagger.io/specification/) documentation and input validators with [Ajv](ajv.js.org/) for [express](https://expressjs.com/) server from [TypeScript](https://www.typescriptlang.org/) project.\n\n## Installation\n\n```\nnpm install --save-dev typescript-routes-to-openapi\nnpm install typescript-routes-to-openapi-server\n```\n\n## Usage\n\n### Create configuration file\n\n`typescript-routes-to-openapi.json`\n\n```json\n{\n  \"openapi\": {\n    \"info\": {\n      \"version\": \"1.0.0\",\n      \"title\": \"Swagger Petstore\",\n      \"description\": \"A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification\",\n      \"termsOfService\": \"http://swagger.io/terms/\",\n      \"contact\": {\n        \"name\": \"Swagger API Team\",\n        \"email\": \"apiteam@swagger.io\",\n        \"url\": \"http://swagger.io\"\n      },\n      \"license\": {\n        \"name\": \"Apache 2.0\",\n        \"url\": \"https://www.apache.org/licenses/LICENSE-2.0.html\"\n      }\n    },\n    \"servers\": [\n      {\n        \"url\": \"http://petstore.swagger.io/api\"\n      }\n    ]\n  },\n  \"tsConfigPath\": \"tsconfig.json\",\n  \"generateOpenApiSchema\": true,\n  \"checkProgramForErrors\": true,\n  \"schemaOutputDir\": \"./\",\n  \"schemaOutputFileName\": \"openapi.json\",\n  \"routesOutputDir\": \"generated\",\n  \"routesOutputFileName\": \"routes.ts\"\n}\n```\n\n### Create controller\n\n```TypeScript\nimport { createExpressRoute } from 'typescript-routes-to-openapi-server';\n\ntype NewPet = {\n  name: string;\n  tag?: string;\n};\n\ntype Pet = NewPet \u0026 {\n  id: number;\n};\n\nexport class PetController {\n  findPets = createExpressRoute\u003c{\n    path: '/pets';\n    method: 'get';\n    requestQuery: {\n      /**\n       * @description tags to filter by\n       */\n      tags?: string[];\n      /**\n       * @description maximum number of results to return\n       */\n      limit?: number;\n    };\n    /**\n     * @description pet response\n     */\n    responseBody: Pet[];\n  }\u003e((req, res) =\u003e {\n    res.send([\n      {\n        id: 1,\n        name: 'Garfield',\n        tag: 'cat',\n      },\n    ]);\n  });\n\n  /**\n   * @description Returns a user based on a single ID, if the user does not have access to the pet\n   * @openapi_operationId find pet by id\n   */\n  findPetById = createExpressRoute\u003c{\n    path: '/pets/:id';\n    method: 'get';\n    pathParams: {\n      /**\n       * @description ID of pet to fetch\n       */\n      id: number;\n    };\n    /**\n     * @description pet response\n     */\n    responseBody: Pet;\n  }\u003e((req, res) =\u003e {\n    res.send({\n      id: 1,\n      name: 'Garfield',\n      tag: 'cat',\n    });\n  });\n\n  /**\n   * @description Creates a new pet in the store. Duplicates are allowed\n   * @openapi_operationId addPet\n   */\n  addPet = createExpressRoute\u003c{\n    path: '/pets';\n    method: 'post';\n    /**\n     * @description Pet to add to the store\n     */\n    requestBody: NewPet;\n    /**\n     * @description pet response\n     */\n    responseBody: Pet[];\n  }\u003e((req, res) =\u003e {\n    res.send([\n      {\n        id: 1,\n        name: 'Garfield',\n        tag: 'cat',\n      },\n    ]);\n  });\n}\n\n```\n\n### Generate routes and OpenApi document\n\n```\nnpx typescript-routes-to-openapi generate\n```\n\n### Include generated routes in your express application\n\n```TypeScript\nimport express from 'express';\nimport { generatedRoutes } from './generated/routes';\n\nconst app = express();\nconst PORT = 8888;\n\napp.use(express.json());\napp.use(generatedRoutes);\n\napp.listen(PORT, () =\u003e {\n  console.log('Listening on', PORT);\n});\n\n```\n\nSee [example](examples/petstore-express)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbonukai%2Ftypescript-routes-to-openapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbonukai%2Ftypescript-routes-to-openapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbonukai%2Ftypescript-routes-to-openapi/lists"}