# doc-catcher

> An express middleware that generates OpenAPI documentation by parsing successful API calls.

Latest version **4.1.4** (published 2022-07-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install doc-catcher
pnpm add doc-catcher
yarn add doc-catcher
bun add doc-catcher
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.4 |
| Published | 2022-07-19 |
| First published | 2022-07-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 31.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Hardik Rajpal |
| Maintainers | myth-childs-apprentice |

## Links

- npm: https://www.npmjs.com/package/doc-catcher
- npm.io page: https://npm.io/package/doc-catcher

## Dependencies (2)

- [express](https://npm.io/package/express.md) ^4.18.1
- [routing-controllers](https://npm.io/package/routing-controllers.md) ^0.9.0

## Recent versions

- 4.1.4 (latest) — 2022-07-19
- 4.1.3 — 2022-07-19
- 4.1.2 — 2022-07-19
- 4.1.1 — 2022-07-19
- 4.1.0 — 2022-07-19
- 4.0.0 — 2022-07-19
- 3.0.1 — 2022-07-19
- 3.0.0 — 2022-07-19
- 2.0.0 — 2022-07-19
- 1.1.3 — 2022-07-19
- 1.1.2 — 2022-07-19
- 1.1.1 — 2022-07-19
- 1.1.0 — 2022-07-19
- 1.0.0 — 2022-07-19

## README

# Setup
After installing the package, create a new file `api_spec_config.json` in the folder that contains your **package.json** file. The contents of the new file should be as follows:
```
{
    "specfile":"./src/constants/APISpec.json",
    "updateSpecs":true
}
```
`specfile` specifies the location of the file in which the updated documentation is to be written.

`updateSpecs` specifies if the documentation is to be updated on new API calls.
## Local Specification
Use the exported middleware `APIDocMiddleware` before the controllers whose transactions you wish to capture for documentation.
```
@JsonController('/route')
@UseBefore(APIDocMiddleware)
export class MyRoutesController{
    ...
}
```

## Global Specification
Specify `middlewares: [APIDocMiddleware]` in `createExpressServer`

## Swagger Integration
And here's the setup in the app.ts file:

```
import swaggerUi from 'swagger-ui-express';
import { readFileSync } from "fs";
import { APIDocMiddleware } from "doc-catcher";
const app: express.Application = createExpressServer({
    cors: {
        origin: ...,
        methods: "GET,POST,PUT,PATCH,DELETE",
        credentials: true
    },
    controllers: [__dirname + "/controllers/**"],
    /*
    just for global integration:
    middlewares: [APIDocMiddleware]
    */
});
if (nodeEnvironment !== "production") {
    app.use('/docs', swaggerUi.serve, swaggerUi.setup(
        JSON.parse(
        readFileSync(
        APIDocMiddleware.specPath,
        { encoding: 'utf-8', flag: 'r' }
        )
        )
    ))
}
export default app;
```
## Testing and Setup
The contents of the `APISpec.json` when it's created
```
{
  "openapi": "3.0.1",
  "info": {
    "version": "1.0.0",
    "title": "REST API for 'the repository to replace all repositories'",
    "description": "This is the REST API for my repository. It isn't entirely useless."
  },
  "servers": [],
  "tags": [],
  "paths": {}
}
```

---
_Source: https://npm.io/package/doc-catcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
