Question: I inherited an existing API and I would like to document it with swagger, but I don't yet know the full scope of it. Can Swagger (or another middleware/tool) auto-magically generate the yaml (for swagger) based on the existing express routes?

For what I saw on other questions, it would appear that this is mostly a manual job, but I'm double-checking if someone here found a way around this.

Answer: 
With [express-sitemap-html](https://www.npmjs.com/package/express-sitemap-html) you may automatically generate a minimalistic Open API definition (only including route parameters) and install a Swagger UI for all routes of an existing express app. You only need:

```js
const sitemap = require('express-sitemap-html')
...
sitemap.swagger('Your app name', app) // given that app is an express instance

```

Instead of analyzing HTTP requests at runtime, this approach inspects express `app` instance and mounted routes.

**PROs** you don't need to perform ahead requests to get an updated list of available routes.

**CONs** it provides untyped parameters features.
Have a look to [swagger-jsdoc](https://github.com/Surnet/swagger-jsdoc). It's a different approach.

The docs stick to the code, and also lets the express code to remain pure.

Guides:

* <https://dev.to/acanimal/express-api-with-autogenerated-openapi-doc-through-swagger-7na>
* <https://dev.to/akshendra/generating-documentation-on-the-fly-in-express-2652>