typescript-rest-swagger is a utility designed to generate OpenAPI (Swagger) specification files directly from projects built with the typescript-rest framework. It analyzes typescript-rest decorators, along with its own set of typescript-rest-swagger decorators (like @Tags, @Response, @Example), and JSDoc comments to construct comprehensive API documentation. The current stable version is 1.1.7, with recent releases focusing on bug fixes and dependency updates, indicating a maintenance-oriented release cadence. Its primary differentiator is its deep integration with typescript-rest, streamlining the documentation process for services developed using that specific REST framework by leveraging existing code annotations rather than requiring a separate definition language.
npm install typescript-rest-swaggerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a simple `typescript-rest` service enhanced with `typescript-rest-swagger` decorators (`@Tags`, `@Response`) and JSDoc for OpenAPI documentation. To generate the `swagger.json` file: 1. Install `typescript-rest` and `reflect-metadata` in your project (`npm i typescript-rest reflect-metadata`). 2. Globally install `typescript-rest-swagger` (`npm i -g typescript-rest-swagger`). 3. Create a `swaggerConfig.json` (e.g., `{ "swagger": { "outputDirectory": "./dist", "entryFile": "./src/services/MyService.ts" } }`). 4. Ensure `tsconfig.json` has `"experimentalDecorators": true`, `"emitDecoratorMetadata": true`, and appropriate `"lib"` settings (e.g., `"es2018", "dom"`). 5. Run `swaggerGen -c ./swaggerConfig.json -p ./tsconfig.json`.
Prefer `npx swaggerGen` to ensure the project's locally installed version is used, or ensure global and local versions are aligned. For project-specific needs, consider adding it as a dev dependency and running via npm scripts.
Always check compatibility notes between 'typescript-rest-swagger' and 'typescript-rest' versions. Pin major versions of both packages in your project to avoid unexpected breaks.
Ensure `experimentalDecorators: true`, `emitDecoratorMetadata: true`, and appropriate `lib` entries (e.g., `es2018`, `dom`) are set. For custom module resolution, properly configure `baseUrl` and `paths` in `tsconfig.json` and pass it with the `-p` flag.
Adopt consistent and comprehensive JSDoc practices. Use `@param`, `@returns`, and general descriptions for classes and methods to enrich the generated documentation.
Run `npm install -g typescript-rest-swagger` to install it globally, or use `npx typescript-rest-swagger` to execute the local package without global installation.
Install `typescript-rest` in your project: `npm install typescript-rest` (or `yarn add typescript-rest`). Also ensure `reflect-metadata` is installed and imported once at your application's entry point.
Update `typescript-rest-swagger` to version 1.1.4 or newer: `npm install typescript-rest-swagger@latest`. If the issue persists, review your service types for potential complexities or circular dependencies.
Verify the `entryFile` path in `swaggerConfig.json`. If using `tsconfig.json`, ensure its `compilerOptions.baseUrl` and `compilerOptions.paths` are correctly configured for your project's module resolution.