z0mt3c/node-restify-swagger — pull request #17 by metasection (2014-12-06 19:07:49+00:00)
Title: Add authorizations property to route definition and support for third party authorizations plugin

This Pull Request addresses issue #11.

# Usage / Implementation

- You can optionally add an ‘authorizations’ parameter to each route with a space separated list of route-authorizations (Example: "admin super-admin").

```javascript
server.get({url: '/test/method/:data',
authorizations: 'account',
swagger: {
summary: 'Get',
notes: '',
nickname: 'getTest'
},
validation: {
data: { isRequired: true, description: 'Data', swaggerType: 'string', scope: 'path' }
}}, function(req, res, next) {
res.send( { data : "get" });
});
```

- The authorizations are listed in the swagger resources.json.

```
"resourcePath": "/swagger/test",
"apis": [
{
"path": "/test/method/{data}",
"description": "",
"operations": [
{
"notes": null,
"nickname": "getTest",
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"responseMessages": [
{
"code": 500,
"message": "Internal Server Error"
}
],
"parameters": [
{
"type": "string",
"dataType": "string",
"name": "data",
"description": "Data",
"required": true,
"paramType": "path"
}
],
"authorizations": {
"type": "account"
},
"summary": "Get",
"httpMethod": "GET",
"method": "GET"
}
]
}
```

- when swagger loads it will optionally call a third party plugin to verify the api_key (if provided) and user authorizations.

- configuring the third party plugin is done by passing the 'authorizationsPlugin' in the configuration options.

```
restifySwagger.configure(server, {
info: {
contact: 'email@domain.tld',
description: 'Description text',
license: 'MIT',
licenseUrl: 'http://opensource.org/licenses/MIT',
termsOfServiceUrl: 'http://opensource.org/licenses/MIT',
title: 'Node Restify Swagger Demo'
},
apiDescriptions: {
'get':'GET-Api Resourcen'
},
authorizationsPlugin: swaggerAuthorizations
});
```