title: Swagger.js Cannot read property 'get' of null
body: <p>I am trying to create a Swagger spec and application for my express api. My app.js file is:</p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  
  var routes = require('./routes/index');
  var users = require('./routes/users');
  var tenants = require('./routes/tenants');
  
  var models = require('./models.js');
  var resources = require('./resources.js')
  
  var app = express();
  var swagger = require('swagger-node-express').createNew(app);
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  // uncomment after placing your favicon in /public
  //app.use(favicon(__dirname + '/public/favicon.ico'));
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  swagger.addModels(models);
  swagger.addGet(resources.getTenantById);//This is where I am getting the error
  
  swagger.setApiInfo({
    title: "Swagger Sample App",
    description: "This is a sample server Petstore server. You can find out more about Swagger at &lt;a href=\"http://swagger.wordnik.com\"&gt;http://swagger.wordnik.com&lt;/a&gt; or on irc.freenode.net, #swagger.  For this sample, you can use the api key \"special-key\" to test the authorization filters",
    termsOfServiceUrl: "http://helloreverb.com/terms/",
    contact: "apiteam@wordnik.com",
    license: "Apache 2.0",
    licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.html"
  });
  
  swagger.configureSwaggerPaths("", "api-docs", "")
  swagger.configure("http://localhost:8002", "1.2.0");
  
  app.use('/', routes);
  app.use('/users', users);
  app.use('/tenants',tenants);
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
      var err = new Error('Not Found');
      err.status = 404;
      next(err);
  });
  
  // error handlers
  
  // development error handler
  // will print stacktrace
  if (app.get('env') === 'development') {
      app.use(function(err, req, res, next) {
          res.status(err.status || 500);
          res.render('error', {
              message: err.message,
              error: err
          });
      });
  }
  
  // production error handler
  // no stacktraces leaked to user
  app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      res.render('error', {
          message: err.message,
          error: {}
      });
  });
  
  
  app.listen(8002);
  </code></pre>
  
  <p>My resources.js file is :</p>
  
  <pre><code>var sw = require('./node_modules/swagger-node-express/Common/node');
  var swe = sw.swagger.errors;
  var params = sw.paramTypes;
  var url = require('url');
  
  exports.getTenantById = {
      'spec' : {
          description : "Operations on Tenants",
          path : "tenants/{tenantId}",
          method : "GET",
          nickname : "getTenantById",
          summary : "Find Tenant by Id",
          notes : "Returns a tenant by Id",
          type : "Tenant",
          produces : ["application/json"],
          parameters : [params.path("tenantId","ID of the Tenant","string")],
          responseMessages : [swe.invalid('tenantId')]
      },
      'action' : function(req,res){
          if(!req.params.tenantId){
              console.log("Tenants Id not provided");
              return res;
          }
  
          var tenant = {
              "id" : res.params.tenantId
          }
  
          res.send(JSON.stringify(tenant));
      }
  };
  </code></pre>
  
  <p>My package.json file:</p>
  
  <pre><code>{
    "name": "myapp",
    "version": "0.0.0",
    "private": true,
    "scripts": {
      "start": "node ./bin/www"
    },
    "dependencies": {
      "body-parser": "~1.10.2",
      "cookie-parser": "~1.3.3",
      "debug": "~2.1.1",
      "express": "~4.11.1",
      "jade": "~1.9.1",
      "morgan": "~1.5.1",
      "serve-favicon": "~2.2.0",
      "swagger-node-express": "~2.0"  
    }
  }
  </code></pre>
  
  <p>The link to swagger-node-express : <a href="https://github.com/swagger-api/swagger-node-express" rel="nofollow">https://github.com/swagger-api/swagger-node-express</a></p>
  
  <p>And the error I am getting after running node app.js command:</p>
  
  <pre><code>Users/deepaksharma/Documents/PROGRAMMING/sample-express-app/myapp/node_modules/swagger-node-express/Common/node/swagger.js:446
      app[currentMethod](fullPath, function (req, res, next) {
         ^
  TypeError: Cannot read property 'get' of null
      at Swagger.addMethod (/Users/deepaksharma/Documents/PROGRAMMING/sample-express-app/myapp/node_modules/swagger-node-express/Common/node/swagger.js:446:8)
      at /Users/deepaksharma/Documents/PROGRAMMING/sample-express-app/myapp/node_modules/swagger-node-express/Common/node/swagger.js:495:10
      at Function.forOwn (/Users/deepaksharma/Documents/PROGRAMMING/sample-express-app/myapp/node_modules/swagger-node-express/node_modules/lodash/dist/lodash.js:1301:15)
      at Swagger.addHandlers (/Users/deepaksharma/Documents/PROGRAMMING/sample-express-app/myapp/node_modules/swagger-node-express/Common/node/swagger.js:493:5)
      at Swagger.addGet.Swagger.addGET (/Users/deepaksharma/Documents/PROGRAMMING/sample-express-app/myapp/node_modules/swagger-node-express/Common/node/swagger.js:520:8)
      at Object.&lt;anonymous&gt; (/Users/deepaksharma/Documents/PROGRAMMING/sample-express-app/myapp/app.js:31:9)
      at Module._compile (module.js:460:26)
      at Object.Module._extensions..js (module.js:478:10)
      at Module.load (module.js:355:32)
      at Function.Module._load (module.js:310:12)
  </code></pre>
  
  <p>I cannot understand why I am getting a null error? </p>