1.0.1 • Published 6 years ago

express-swagger-role v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Express Swagger Role

Middleware for swagger definition driven role system.

Install

npm install express-swagger-role --save

Usage

The package check the req.user.role property of endpoint handler and the x-roles array property of the swagger file.

as middleware

const expressSwaggerRole = require('express-swagger-role');

app.use(expressSwaggerRole.middleware());

as method

const expressSwaggerRole = require('express-swagger-role');

app.get('/', (req, res) => {
  if (exporessSwaggerRole.roleChecker(req)) {
    console.log('This log run only for admins');
  }
});

swagger configuration:

{
  "paths": {
    "/": {
      "get": {
        "x-roles": ["admin"],
        "responses": {
          "200": {
            "description": "Test endpoint"
          }
        }
      }
    }
  }
}
1.0.1

6 years ago

1.0.0

6 years ago