Quick Start

Installation

npm install swagger-stats --save
1

Express

Enable swagger-stats middleware in your Express App:

var swStats = require('swagger-stats');    

// Load your swagger specification 
var apiSpec = require('./swagger.json');

// Enable swagger-stats middleware in express app, passing swagger specification as option 
app.use(swStats.getMiddleware({swaggerSpec:apiSpec}));
1
2
3
4
5
6
7

See Express Sample Application

Start Monitoring

Navigate to http://<your app host:port>/swagger-stats/ui

dashboard

Fastify

const swStats = require('swagger-stats');
const apiSpec = require('./swagger.json');

const fastify = require('fastify')({
    logger: true
});

fastify.register(swStats.getFastifyPlugin, {swaggerSpec:apiSpec});
1
2
3
4
5
6
7
8

See Fastify Sample Application

Koa

You will need express-to-koa to use swagger-stats middleware in your Koa app

var swStats = require('swagger-stats');
var apiSpec = require('./swagger.json');
var e2k = require('express-to-koa');

app.use(e2k(swStats.getMiddleware({ swaggerSpec:apiSpec })));
1
2
3
4
5

Hapi

Register swagger-stats Hapi plugin in your Hapi app

const swStats = require('swagger-stats');
const swaggerSpec = require('./petstore.json');

const init = async () => {

    server = Hapi.server({
        port: 3040,
        host: 'localhost'
    });

    await server.register({
        plugin: swStats.getHapiPlugin,
        options: {
             swaggerSpec:swaggerSpec
        }
    });

    await server.start();
    console.log('Server running on %s', server.info.uri);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

See Hapi sample application