# organic-express-api-doc

> Organelle for generating documentation by runtime reflection of express mounted route handlers and their source code.

Latest version **1.0.0** (published 2016-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install organic-express-api-doc
pnpm add organic-express-api-doc
yarn add organic-express-api-doc
bun add organic-express-api-doc
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-07-20 |
| First published | 2015-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Boris Filipov |
| Maintainers | outbounder |

## Links

- npm: https://www.npmjs.com/package/organic-express-api-doc
- Repository: https://github.com/outbounder/organic-express-api-doc
- Issues: https://github.com/outbounder/organic-express-api-doc/issues
- npm.io page: https://npm.io/package/organic-express-api-doc

## Dependencies (11)

- [ejs](https://npm.io/package/ejs.md) ^2.0.8
- [async](https://npm.io/package/async.md) ^1.5.0
- [lodash](https://npm.io/package/lodash.md) ^3.10.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [esprima](https://npm.io/package/esprima.md) ^2.7.1
- [methods](https://npm.io/package/methods.md) ^1.1.1
- [markedejs](https://npm.io/package/markedejs.md) ~0.1.0
- [glob-stream](https://npm.io/package/glob-stream.md) ^5.3.1
- [organic-plasma](https://npm.io/package/organic-plasma.md) ^1.0.0
- [organic-nucleus](https://npm.io/package/organic-nucleus.md) ^1.0.0
- [express-buffer-response](https://npm.io/package/express-buffer-response.md) ^1.0.3

## Recent versions

- 1.0.0 (latest) — 2016-07-20
- 0.3.0 — 2015-12-26
- 0.2.3 — 2015-06-23
- 0.2.2 — 2015-06-09
- 0.2.1 — 2015-02-23
- 0.2.0 — 2015-02-23
- 0.1.3 — 2015-02-22
- 0.1.2 — 2015-02-12
- 0.1.1 — 2015-02-12
- 0.1.0 — 2015-02-11
- 0.0.2 — 2015-01-14
- 0.0.1 — 2015-01-10

## README

# organic-express-api-doc v0.3.0

Organelle for generating documentation by runtime reflection of express mounted route handlers and their source code.

## dna

    {
      "source": "node_modules/organic-express-api-doc",
      "reactOn": ["ExpressServer"],
      "mountOn": "/api-docs",
      "routes": {
        "organic-api-routes": "@processes.index.plasma.organic-api-routes"
      },
      "docsMetadata": {
        "source": "docs/api",
        "autopopulate": false,
        "renderAutopopulatedDocs": false,
        "populateFilename": "api.md"
      },
      "log": false,
      "liveTemplateReload": false,
      "templatePath": String // defaults to path.join(organic-express-api-doc, "../template/index.html")
    }

## `routes` property

Its value is used to build organelles responsible for [express routes mounting](https://github.com/outbounder/organic-express-routes).

**All organelles are expected to `reactOn` and to `emitReady`. Additionally `log: false` is applied to their corresponding dna before triggering their build.**

## `docsMetadata` property

Indicates additional metadata information by default stored in markdown files where api routes are matched as follows

    ... any markdown content ...
    ## METHOD route
    ... markdown content for api action
    ...

So for example given the markdown bellow:

    # markdown file title

    ## GET /api/resource

    this text will be merged as description for `GET /api/resource` action,
    other supported methods are "POST", "PUT", "DELETE" and "ALL"

    ## PUT /api/resource/:url_param ? :query_params

    example markdown metadata description for action with url and query params.

    ### url params

    * :url_param

    ### query params

    * :query_params

Will be extracted metadata information for the following routes:

* GET /api/resource
* PUT /api/resource/:url_param

**Notice** that methods and urls should exactly match to your mounted express route handlers (case sensitive ;)

### `autopopulate` property

When enabled will intercept all incoming requests and their responses and upon `kill` chemical will dump at `dna.docsMetadata` `{.source} \ {.populateFilename}.json` json data documentation with samples 'schemified'.

### `renderAutopopulatedDocs` property

When enabled will load and render `dna.docsMetadata` `{.source} \ {.populateFilename}.json` json data documentation into `dna.docsMetadata` `{.source} \ {.populateFilename}` markdown file suitable
for parsing by docsMetadata pipeline.

*Noteice* that this happens when the organelle is constructed, therefore it won't output anything if the json file is missing.


## under-the-hood

### the concept

#### sampling routes

0. load `sampled routes metadata` if exists
1. intercept all incoming http requests and their respective responses
2. convert their properties (`headers`, `body`, ...) to a schema-like structures
3. consolidate requests/responses into samples per `method` : `route`
4. store `sampled routes metadata`

#### structure routes map

1. intercept Express app's mount methods (`all`, `get`, `post`, ...)
2. analyze the handlers passed
3. stored `sampled routes metadata` is loaded and trasnformed to markdown file
4. load markdown files and transform them to `routes metadata`
5. generate `in-memory documentation structure` of analyzed routes forming their respective apis with their `routes metadata`

#### documentation rendering

1. mount route handler on Express app
2. respond with `in-memory documentation structure` transformed as `html+css+js` to incoming requests

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