All files / lib/routes _swagger.js

45.45% Statements 5/11
0% Branches 0/4
0% Functions 0/2
50% Lines 5/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22  1x   1x 1x 1x   1x                            
'use strict'
const swagger = module.exports = { }
 
const router = require('../router.js')
const swaggerGenerator = require('../swagger')
const jsonApi = require('../../')
 
swagger.register = () => {
  if (!jsonApi._apiConfig.swagger) return
 
  router.bindRoute({
    verb: 'get',
    path: 'swagger.json'
  }, (request, resourceConfig, res) => {
    if (!swagger._cache) {
      swagger._cache = swaggerGenerator.generateDocumentation()
    }
 
    return res.json(swagger._cache)
  })
}