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) {
return {
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,
// TODO(schoon) - We don't have descriptions for this yet.
responseMessages: [],
summary: route.description, // TODO(schoon) - Excerpt?
notes: '' // TODO(schoon) - `description` metadata?
summary: route.description,
notes: route.notes,
deprecated: route.deprecated
})]
};

View File

@ -28,8 +28,17 @@ function Swagger(loopbackApplication, swaggerApp, opts) {
basePath: loopbackApplication.get('restApiRoot') || '/api',
resourcePath: 'resources',
// Default consumes/produces
consumes: ['application/json', 'application/x-www-form-urlencoded'],
produces: ['application/json'],
consumes: [
'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()
});
@ -101,17 +110,17 @@ function addRoute(app, uri, doc, opts) {
app.get(urlJoin('/', uri), function(req, res) {
// There's a few forces at play that require this "hack". The Swagger spec
// requires a `basePath` to be set in the API descriptions. However, we
// can't guarantee this path is either reachable or desirable if it's set
// requires a `basePath` to be set in the API descriptions. However, we
// can't guarantee this path is either reachable or desirable if it's set
// as a part of the options.
//
//
// The simplest way around this is to reflect the value of the `Host` HTTP
// header as the `basePath`. Because we pre-build the Swagger data, we don't
// know that header at the time the data is built.
if (hasBasePath) {
var headers = req.headers;
var host = headers.Host || headers.host;
doc.basePath = (opts.protocol || req.protocol) + '://' +
doc.basePath = (opts.protocol || req.protocol) + '://' +
host + initialPath;
}
res.status(200).send(doc);
@ -147,7 +156,7 @@ function getVersion() {
try {
version = require(path.join(process.cwd(), 'package.json')).version;
} catch(e) {
version = '';
version = '1.0.0';
}
return version;
}

View File

@ -75,6 +75,19 @@ describe('route-helper', function() {
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

View File

@ -104,6 +104,33 @@ describe('swagger definition', function() {
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() {