Merge pull request #58 from strongloop/godaddy-improvements-1
Godaddy improvements - round 1
This commit is contained in:
commit
72f36b56bf
|
@ -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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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
|
||||||
})]
|
})]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -101,17 +110,17 @@ function addRoute(app, uri, doc, opts) {
|
||||||
app.get(urlJoin('/', uri), function(req, res) {
|
app.get(urlJoin('/', uri), function(req, res) {
|
||||||
|
|
||||||
// There's a few forces at play that require this "hack". The Swagger spec
|
// 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
|
// 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
|
// can't guarantee this path is either reachable or desirable if it's set
|
||||||
// as a part of the options.
|
// as a part of the options.
|
||||||
//
|
//
|
||||||
// The simplest way around this is to reflect the value of the `Host` HTTP
|
// 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
|
// header as the `basePath`. Because we pre-build the Swagger data, we don't
|
||||||
// know that header at the time the data is built.
|
// know that header at the time the data is built.
|
||||||
if (hasBasePath) {
|
if (hasBasePath) {
|
||||||
var headers = req.headers;
|
var headers = req.headers;
|
||||||
var host = headers.Host || headers.host;
|
var host = headers.Host || headers.host;
|
||||||
doc.basePath = (opts.protocol || req.protocol) + '://' +
|
doc.basePath = (opts.protocol || req.protocol) + '://' +
|
||||||
host + initialPath;
|
host + initialPath;
|
||||||
}
|
}
|
||||||
res.status(200).send(doc);
|
res.status(200).send(doc);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue