Made API doc of class use the http.path of the class if available, or the name of the class as a fallback

This commit is contained in:
gandrianakis 2015-02-17 17:23:32 +02:00
parent 4d4ac3860f
commit 16c54c038e
2 changed files with 30 additions and 5 deletions

View File

@ -23,11 +23,16 @@ var classHelper = module.exports = {
* @return {Object} API Declaration.
*/
generateAPIDoc: function(aClass, opts) {
var resourcePath = urlJoin('/', aClass.name);
if(aClass.http && aClass.http.path) {
resourcePath = aClass.http.path;
}
return {
apiVersion: opts.version,
swaggerVersion: opts.swaggerVersion,
basePath: opts.basePath,
resourcePath: urlJoin('/', opts.resourcePath),
resourcePath: urlJoin('/', resourcePath),
apis: [],
consumes: aClass.http.consumes || opts.consumes,
produces: aClass.http.produces || opts.produces,

View File

@ -12,12 +12,32 @@ describe('class-helper', function() {
expect(doc.description).to.equal('line1\nline2');
});
it('sets resourcePath from aClass.http.path', function() {
var doc = generateAPIDoc({}, 'otherPath');
expect(doc.resourcePath).to.equal('/otherPath');
});
it('sets resourcePath from aClass.name', function() {
var doc = generateAPIDoc({});
expect(doc.resourcePath).to.equal('/test');
});
});
// Easy wrapper around createRoute
function generateResourceDocAPIEntry(def) {
return classHelper.generateResourceDocAPIEntry(_defaults(def, {
http: { path: '/test' },
ctor: { settings: { } },
ctor: { settings: { } }
}));
}
function generateAPIDoc(def, httpPath) {
return classHelper.generateAPIDoc(_defaults(def, {
http: { path: httpPath || null },
name: 'test',
ctor: { settings: { } }
}), {resourcePath: 'resources'});
}