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:
parent
4d4ac3860f
commit
16c54c038e
|
@ -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,
|
||||
|
|
|
@ -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'});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue