diff --git a/ext/swagger.js b/ext/swagger.js index 1f28cead..1586c715 100644 --- a/ext/swagger.js +++ b/ext/swagger.js @@ -36,7 +36,7 @@ function Swagger(remotes, options, models) { classes.forEach(function (item) { resourceDoc.apis.push({ - path: '/' + name + '/' + item.name, + path: '/' + name + item.http.path, description: item.ctor.sharedCtor && item.ctor.sharedCtor.description }); @@ -50,6 +50,7 @@ function Swagger(remotes, options, models) { helper.method(api, { path: item.name, + http: { path: item.http.path }, returns: { type: 'object', root: true } }); function api(callback) { diff --git a/lib/shared-class.js b/lib/shared-class.js index 515a6b7c..ad20154e 100644 --- a/lib/shared-class.js +++ b/lib/shared-class.js @@ -32,6 +32,8 @@ function SharedClass(name, ctor) { assert(ctor.sharedCtor, 'must define a sharedCtor'); this.sharedCtor = new SharedMethod(ctor.sharedCtor, 'sharedCtor'); } + + this.http = util._extend({ path: '/' + this.name }, ctor.http); assert(this.name, 'must include a remoteNamespace when creating a SharedClass'); } @@ -77,4 +79,4 @@ function eachRemoteFunctionInObject(obj, f) { f(fn, key); } } -} \ No newline at end of file +} diff --git a/test/shared-class.test.js b/test/shared-class.test.js new file mode 100644 index 00000000..d44d32d0 --- /dev/null +++ b/test/shared-class.test.js @@ -0,0 +1,22 @@ +var extend = require('util')._extend; +var expect = require('chai').expect; +var SharedClass = require('../lib/shared-class'); +var factory = require('./helpers/shared-objects-factory.js'); + +describe('SharedClass', function() { + var SomeClass; + beforeEach(function() { SomeClass = factory.createSharedClass(); }); + + describe('constructor', function() { + it('fills http.path from ctor.http', function() { + SomeClass.http = { path: '/foo' }; + var sc = new SharedClass('some', SomeClass); + expect(sc.http.path).to.equal('/foo'); + }); + + it('fills http.path using the name', function() { + var sc = new SharedClass('some', SomeClass); + expect(sc.http.path).to.equal('/some'); + }); + }); +});