Skip to content

DrRaider/api-doc-generator-on-tests

 
 

Repository files navigation

Document your API while running your tests

MIT License Build Status: Linux

Installation

yarn add api-doc-generator-on-tests

Create API documentation based on Express.js

Simple express example

var express = require('express');
var Markdown = require('api-doc-generator-on-tests');

var app = express();

Markdown({
      express: app,
      path: '/api.md', // path to API API documentation
      storeResponses: true, // store first response as example
      guessAll: true, // make description quite pretty
      title: 'docTitle',
    });

// regular app express workflow ( app.get, app.post, app.listen... etc )

Add doc generation on each route test

before(async () => {
    server = await createServer({ docTitle: 'Best API Ever' });
  });

  after(async () => {
    const documentation = await apiRequest.get('api.md');
    await fs.writeFile(`${__dirname}/../../../documentation/best-api-ever.md`, documentation.text);
    await closeServer(server);
  });

// run your tests  

Result example

# Methods

## Brief
 - [/api.md](#methods./api.md)
   - get
 - [/movies](#methods./movies)
   - get
   - post
 - [/movies/:id](#methods./movies/:id)
   - get
   - delete

##  /api.md
Method | Description
-------|------------
get | get /api.md


##  /movies
Method | Description
-------|------------
get | get /movies
post | post /movies

##  /movies/{id}
Method | Description
-------|------------
get | get /movies/:id
delete | delete /movies/:id
```

Options parameters

var md = new Markdown(options);
  • express - an Express application
  • path - path to get API API documentation ( default: /api.md )
  • storeResponses - store first response as example ( default: false )
  • guessAll - make description quite pretty ( default: false )
  • title - title of API in document

Tests

yarn test

Change Log

all changes

Created by

Nicolas SAILLY

About

Create markdown API documentation from Express while running tests

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%