Merge pull request #58 from strongloop/godaddy-improvements-1

Godaddy improvements - round 1
This commit is contained in:
Miroslav Bajtoš 2014-10-13 18:46:57 +02:00
commit 72f36b56bf
5 changed files with 61 additions and 10 deletions

View File

@ -43,7 +43,8 @@ var classHelper = module.exports = {
generateResourceDocAPIEntry: function(aClass) { generateResourceDocAPIEntry: function(aClass) {
return { return {
path: aClass.http.path, path: aClass.http.path,
description: aClass.ctor.sharedCtor && aClass.ctor.sharedCtor.description description: aClass.ctor.settings.description ||
aClass.ctor.sharedCtor && aClass.ctor.sharedCtor.description
}; };
} }
}; };

View File

@ -137,8 +137,9 @@ var routeHelper = module.exports = {
parameters: accepts, parameters: accepts,
// TODO(schoon) - We don't have descriptions for this yet. // TODO(schoon) - We don't have descriptions for this yet.
responseMessages: [], responseMessages: [],
summary: route.description, // TODO(schoon) - Excerpt? summary: route.description,
notes: '' // TODO(schoon) - `description` metadata? notes: route.notes,
deprecated: route.deprecated
})] })]
}; };

View File

@ -28,8 +28,17 @@ function Swagger(loopbackApplication, swaggerApp, opts) {
basePath: loopbackApplication.get('restApiRoot') || '/api', basePath: loopbackApplication.get('restApiRoot') || '/api',
resourcePath: 'resources', resourcePath: 'resources',
// Default consumes/produces // Default consumes/produces
consumes: ['application/json', 'application/x-www-form-urlencoded'], consumes: [
produces: ['application/json'], 'application/json',
'application/x-www-form-urlencoded',
'application/xml', 'text/xml'
],
produces: [
'application/json',
'application/xml', 'text/xml',
// JSONP content types
'application/javascript', 'text/javascript'
],
version: getVersion() version: getVersion()
}); });
@ -147,7 +156,7 @@ function getVersion() {
try { try {
version = require(path.join(process.cwd(), 'package.json')).version; version = require(path.join(process.cwd(), 'package.json')).version;
} catch(e) { } catch(e) {
version = ''; version = '1.0.0';
} }
return version; return version;
} }

View File

@ -75,6 +75,19 @@ describe('route-helper', function() {
expect(opDoc.format).to.equal('byte'); expect(opDoc.format).to.equal('byte');
}); });
it('includes `notes` metadata', function() {
var doc = createAPIDoc({
notes: 'some notes'
});
expect(doc.operations[0].notes).to.equal('some notes');
});
it('includes `deprecated` metadata', function() {
var doc = createAPIDoc({
deprecated: 'true'
});
expect(doc.operations[0].deprecated).to.equal('true');
});
}); });
// Easy wrapper around createRoute // Easy wrapper around createRoute

View File

@ -104,6 +104,33 @@ describe('swagger definition', function() {
done(); done();
}); });
}); });
it('includes `consumes`', function(done) {
var app = mountSwagger();
getAPIDeclaration(app, 'products').end(function(err, res) {
if (err) return done(err);
expect(res.body.consumes).to.have.members([
'application/json',
'application/x-www-form-urlencoded',
'application/xml', 'text/xml'
]);
done();
});
});
it('includes `produces`', function(done) {
var app = mountSwagger();
getAPIDeclaration(app, 'products').end(function(err, res) {
if (err) return done(err);
expect(res.body.produces).to.have.members([
'application/json',
'application/xml', 'text/xml',
// JSONP content types
'application/javascript', 'text/javascript'
]);
done();
});
});
}); });
describe('Cross-origin resource sharing', function() { describe('Cross-origin resource sharing', function() {