apigee-127 / swagger-node-runner

The heart of Swagger-Node
MIT License
102 stars 124 forks source link

Support dependencies injection in router fitting #62

Closed alikh31 closed 8 years ago

alikh31 commented 8 years ago

Just an idea that would make my life much easier. Let the api to inject their dependencies. (additionally would be possible to use tools like electrolyte)

Pass dependencies to create by config object, example:

  config.dependencies = [fs, path, ...]

  SwaggerExpress.create(config, function(err, swaggerExpress) {
    if (err) {
      deps.logger.error(err)
      throw err
    }

    // install middleware
    swaggerExpress.register(app)
  })

The controlle's module exports will look like something like:

module.exports = function(dependencies){
  return {
    hello: hello,
    hello_body: hello_body,
    hello_file: hello_file,
    get: hello,
    multiple_writes: multiple_writes,
    hello_text_body: hello_text_body
  }
};
coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.006%) to 96.321% when pulling c5dfe76f40d8ffba825844a7efd2ab8a07710441 on alikh31:master into 07a706f461833ca1642981a61c8ce72e6a8a260b on theganyo:master.

theganyo commented 8 years ago

I like this enhancement. Is there any way you could include testing?

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.01%) to 96.327% when pulling c0092aa68a6c5492897ec10a3b6b38cf564974b8 on alikh31:master into 07a706f461833ca1642981a61c8ce72e6a8a260b on theganyo:master.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.01%) to 96.327% when pulling b931ae4c43f6203a48a0e1a55de4110bb5b32e5c on alikh31:master into 07a706f461833ca1642981a61c8ce72e6a8a260b on theganyo:master.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.01%) to 96.327% when pulling dca7c1fea4be6858dddf3080f56c0e398a0dee2d on alikh31:master into 07a706f461833ca1642981a61c8ce72e6a8a260b on theganyo:master.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.01%) to 96.327% when pulling dca7c1fea4be6858dddf3080f56c0e398a0dee2d on alikh31:master into 07a706f461833ca1642981a61c8ce72e6a8a260b on theganyo:master.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.01%) to 96.327% when pulling dca7c1fea4be6858dddf3080f56c0e398a0dee2d on alikh31:master into 07a706f461833ca1642981a61c8ce72e6a8a260b on theganyo:master.

alikh31 commented 8 years ago

@theganyo it's quite tricky to add test for this, let me know if the test was confusing

theganyo commented 8 years ago

Nope, looks good. Thanks so much!