Merge branch 'release/1.2.6' into production

This commit is contained in:
Raymond Feng 2014-07-29 08:55:26 -07:00
commit d99f6edf29
5 changed files with 54 additions and 3 deletions

20
example/hidden.js Normal file
View File

@ -0,0 +1,20 @@
var loopback = require('loopback');
var app = loopback();
var explorer = require('../');
var port = 3000;
var User = loopback.Model.extend('user', {
username: 'string',
email: 'string',
sensitiveInternalProperty: 'string',
}, {hidden: ['sensitiveInternalProperty']});
User.attachTo(loopback.memory());
app.model(User);
var apiPath = '/api';
app.use('/explorer', explorer(app, {basePath: apiPath}));
app.use(apiPath, loopback.rest());
console.log('Explorer mounted at localhost:' + port + '/explorer');
app.listen(port);

View File

@ -37,6 +37,12 @@ var modelHelper = module.exports = {
Object.keys(properties).forEach(function(key) { Object.keys(properties).forEach(function(key) {
var prop = properties[key]; var prop = properties[key];
// Hide hidden properties.
if (modelHelper.isHiddenProperty(def, key)) {
delete properties[key];
return;
}
// Eke a type out of the constructors we were passed. // Eke a type out of the constructors we were passed.
prop = modelHelper.LDLPropToSwaggerDataType(prop); prop = modelHelper.LDLPropToSwaggerDataType(prop);
@ -84,6 +90,12 @@ var modelHelper = module.exports = {
return propType; return propType;
}, },
isHiddenProperty: function(definition, propName) {
return definition.settings &&
Array.isArray(definition.settings.hidden) &&
definition.settings.hidden.indexOf(propName) !== -1;
},
// Converts a prop defined with the LDL spec to one conforming to the // Converts a prop defined with the LDL spec to one conforming to the
// Swagger spec. // Swagger spec.
// https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#431-primitives // https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#431-primitives

View File

@ -102,7 +102,7 @@ function addRoute(app, uri, doc) {
var host = headers.Host || headers.host; var host = headers.Host || headers.host;
doc.basePath = req.protocol + '://' + host + initialPath; doc.basePath = req.protocol + '://' + host + initialPath;
} }
res.send(200, doc); res.status(200).send(doc);
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "loopback-explorer", "name": "loopback-explorer",
"version": "1.2.5", "version": "1.2.6",
"description": "Browse and test your LoopBack app's APIs", "description": "Browse and test your LoopBack app's APIs",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -117,10 +117,29 @@ describe('model-helper', function() {
expect(defs).has.property('relatedModel'); expect(defs).has.property('relatedModel');
}); });
}); });
describe('hidden properties', function() {
it('should hide properties marked as "hidden"', function() {
var aClass = createModelCtor({
visibleProperty: 'string',
hiddenProperty: 'string'
});
aClass.ctor.definition.settings = {
hidden: ['hiddenProperty']
};
var def = modelHelper.generateModelDefinition(aClass.ctor, {}).testModel;
expect(def.properties).to.not.have.property('hiddenProperty');
expect(def.properties).to.have.property('visibleProperty');
});
});
}); });
// Simulates the format of a remoting class. // Simulates the format of a remoting class.
function buildSwaggerModels(model) { function buildSwaggerModels(model) {
var aClass = createModelCtor(model);
return modelHelper.generateModelDefinition(aClass.ctor, {}).testModel;
}
function createModelCtor(model) {
Object.keys(model).forEach(function(name) { Object.keys(model).forEach(function(name) {
model[name] = {type: model[name]}; model[name] = {type: model[name]};
}); });
@ -132,7 +151,7 @@ function buildSwaggerModels(model) {
} }
} }
}; };
return modelHelper.generateModelDefinition(aClass.ctor, {}).testModel; return aClass;
} }
function buildSwaggerModelsWithRelations(model) { function buildSwaggerModelsWithRelations(model) {