2014-07-05 19:32:00 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var modelHelper = require('./model-helper');
|
2014-07-10 18:49:09 +00:00
|
|
|
var urlJoin = require('./url-join');
|
2014-07-05 19:32:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Export the classHelper singleton.
|
|
|
|
*/
|
|
|
|
var classHelper = module.exports = {
|
|
|
|
/**
|
|
|
|
* Given a remoting class, generate an API doc.
|
|
|
|
* See https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#52-api-declaration
|
|
|
|
* @param {Class} aClass Strong Remoting class.
|
|
|
|
* @param {Object} opts Options (passed from Swagger(remotes, options))
|
|
|
|
* @param {String} opts.version API Version.
|
|
|
|
* @param {String} opts.swaggerVersion Swagger version.
|
|
|
|
* @param {String} opts.basePath Basepath (usually e.g. http://localhost:3000).
|
|
|
|
* @param {String} opts.resourcePath Resource path (usually /swagger/resources).
|
|
|
|
* @return {Object} API Declaration.
|
|
|
|
*/
|
|
|
|
generateAPIDoc: function(aClass, opts) {
|
|
|
|
return {
|
2014-08-05 01:19:09 +00:00
|
|
|
apiVersion: opts.version || '1',
|
2014-07-05 19:32:00 +00:00
|
|
|
swaggerVersion: opts.swaggerVersion,
|
|
|
|
basePath: opts.basePath,
|
2014-07-10 18:49:09 +00:00
|
|
|
resourcePath: urlJoin('/', opts.resourcePath),
|
2014-07-05 19:32:00 +00:00
|
|
|
apis: [],
|
2014-08-04 04:48:16 +00:00
|
|
|
consumes: aClass.http.consumes || opts.consumes,
|
|
|
|
produces: aClass.http.produces || opts.produces,
|
2014-07-24 20:35:02 +00:00
|
|
|
models: modelHelper.generateModelDefinition(aClass.ctor, {})
|
2014-07-05 19:32:00 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Given a remoting class, generate a reference to an API declaration.
|
|
|
|
* This is meant for insertion into the Resource declaration.
|
|
|
|
* See https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#512-resource-object
|
|
|
|
* @param {Class} aClass Strong Remoting class.
|
|
|
|
* @return {Object} API declaration reference.
|
|
|
|
*/
|
|
|
|
generateResourceDocAPIEntry: function(aClass) {
|
2015-04-07 18:21:12 +00:00
|
|
|
var description = aClass.ctor.settings.description || aClass.ctor.sharedCtor && aClass.ctor.sharedCtor.description;
|
2014-07-05 19:32:00 +00:00
|
|
|
return {
|
|
|
|
path: aClass.http.path,
|
2015-04-07 18:21:12 +00:00
|
|
|
description: Array.isArray(description) ? description.join('') : description
|
2014-07-05 19:32:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|