wordnik/swagger-node-express — pull request #50 by deleteman (2013-04-29 15:09:01+00:00)
Title: Adding before action method

Adds a new type of action to the controllers that will be executed before the actual action of the method.
This helps on adding filters to each controller method.

The motivation for this pull request, is that when trying to use the request validators feature, the validate function needs to return true or false, and thus have no support for async checking inside the validator (i.e: checking against mongodb ).

Sample code:

```javascript
UserController.prototype.findById = function(){
return {
'spec': {
"description" : "description",
"path" : "/user.{format}/{userId}",
"notes" : "Returns an user based on ID",
"summary" : "Find user by ID",
"method": "GET",
"params" : [
swagger.pathParam("userId", "ID of user that needs to be fetched", "string"),
swagger.queryParam("auth_token", "The authentication token obtained afer login in ", "string")
],
"responseClass" : "User",
"errorResponses" : [
swagger.errors.invalid('id'),
swagger.errors.notFound('User`'),
swagger.errors.invalid("auth_token")
],
"nickname" : "getUsersById"
},
'before': function(req, res, action) {
//this code is executed before 'action' and
//validation checks against mongodb, if valid, executes action, otherwise, it
//renders an error message.
validateAuthToken(req, res, action);
} ,
'action': function (req,res) {
//Here goes controller code
}
}
}
}
```