{"action":"created","issue":{"url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/291","labels_url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/291/labels{/name}","comments_url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/291/comments","events_url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/291/events","html_url":"https://github.com/apigee-127/swagger-tools/issues/291","id":112170843,"number":291,"title":"Adding route specific middleware?","user":{"login":"rw12345","id":15198213,"avatar_url":"https://avatars.githubusercontent.com/u/15198213?v=3","gravatar_id":"","url":"https://api.github.com/users/rw12345","html_url":"https://github.com/rw12345","followers_url":"https://api.github.com/users/rw12345/followers","following_url":"https://api.github.com/users/rw12345/following{/other_user}","gists_url":"https://api.github.com/users/rw12345/gists{/gist_id}","starred_url":"https://api.github.com/users/rw12345/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rw12345/subscriptions","organizations_url":"https://api.github.com/users/rw12345/orgs","repos_url":"https://api.github.com/users/rw12345/repos","events_url":"https://api.github.com/users/rw12345/events{/privacy}","received_events_url":"https://api.github.com/users/rw12345/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-19T15:35:30Z","updated_at":"2015-10-21T08:51:17Z","closed_at":"2015-10-21T08:51:17Z","body":"Hi There,\r\nAm I missing something or it's not currently possible to add a route specific middleware?\r\n\r\nLet's say I have an API /users that's used to create a user. \r\nSwagger tools makes it insanely easy to declare the spec, and establish the relationship [1] with a controller that receives the validated params [2] to create the user. So far, so good.\r\n\r\nAs an additional security requirement, I would like to have a middleware that checks if the request for user creation comes from an allowed range of IP addresses. \r\n\r\nIn standard express speak, I'd have had a route middleware on the user post request handler shown in [3].\r\n\r\nHow do I accomplish the same using swagger tools? Looking at https://github.com/apigee-127/swagger-tools/blob/master/docs/Middleware.md, it seems that middleware handler is all or nothing and abstracts away the routes completely.\r\n\r\nThanks!\r\n\r\n[1] Swagger definition\r\n```\r\npaths:\r\n  /users:\r\n    x-swagger-router-controller: userController\r\n    post:\r\n      summary: Creates a new user\r\n      description:\r\n        Creates a new user with the given name.\r\n      operationId: post\r\n      parameters:\r\n        - in: body\r\n          name: body\r\n          description: The user object\r\n          required: true\r\n          schema:\r\n            $ref: \"#/definitions/User\"\r\n...\r\n```\r\n\r\n[2] userController.js\r\n```\r\nfunction post(req, res, next) {\r\n  var body = req.swagger.params.body.value;\r\n  // Create user here...\r\n}\r\nmodule.exports = {\r\n  post: post\r\n...\r\n```\r\n\r\n[3] Simple express app with user create route and IP address checking middleware\r\n```\r\nvar express = require('express');\r\nvar app = express();\r\n\r\n// Middleware function for IP address whitelist checking\r\nvar function checkIPAddressAllowed = function(req, res, next) {\r\n  // Return next with error to disallow\r\n  ...\r\n};\r\n\r\nvar createUser = function(req, res, next) {\r\n  // Create user\r\n  ...\r\n};\r\n\r\napp.post('/users', checkIPAddressAllowed, createUser);\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/comments/149824933","html_url":"https://github.com/apigee-127/swagger-tools/issues/291#issuecomment-149824933","issue_url":"https://api.github.com/repos/apigee-127/swagger-tools/issues/291","id":149824933,"user":{"login":"rw12345","id":15198213,"avatar_url":"https://avatars.githubusercontent.com/u/15198213?v=3","gravatar_id":"","url":"https://api.github.com/users/rw12345","html_url":"https://github.com/rw12345","followers_url":"https://api.github.com/users/rw12345/followers","following_url":"https://api.github.com/users/rw12345/following{/other_user}","gists_url":"https://api.github.com/users/rw12345/gists{/gist_id}","starred_url":"https://api.github.com/users/rw12345/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rw12345/subscriptions","organizations_url":"https://api.github.com/users/rw12345/orgs","repos_url":"https://api.github.com/users/rw12345/repos","events_url":"https://api.github.com/users/rw12345/events{/privacy}","received_events_url":"https://api.github.com/users/rw12345/received_events","type":"User","site_admin":false},"created_at":"2015-10-21T08:51:17Z","updated_at":"2015-10-21T08:51:17Z","body":"@whitlockjc Apologies for the late response and the good news is, you are absolutely correct. \r\nI missed initialising the route handlers before initialising the swagger-router, which obviously led to the weiredness I was seeing. Doh!\r\nMany thanks for the clarification."}}