From 52f8fb34160114be6ca45dd0b4fe092d0f5b45fc Mon Sep 17 00:00:00 2001 From: rashmihunt Date: Tue, 9 May 2017 16:31:54 -0700 Subject: [PATCH] handle excludeBaseProperties --- lib/model-builder.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/model-builder.js b/lib/model-builder.js index 4a8aaee4..3de4a64a 100644 --- a/lib/model-builder.js +++ b/lib/model-builder.js @@ -256,8 +256,18 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett ModelClass.setter = {}; for (var p in properties) { - // Remove properties that reverted by the subclass - if (properties[p] === null || properties[p] === false) { + // e.g excludePropertyList = ['id'] - base properties listed in excludePropertyList will be excluded from the model. + // excludeBaseProperties is introduced in SOAP model generation only for now and below logic + // handles excludeBaseProperties. Generated SOAP model has base as 'Model' which means 'id' property gets added + // automatically and 'id' property shouldn't be there for SOAP models. idInjection = false will not work + // for SOAP generator case, since base 'Model' has already id property. 'id: false' at the property level will not + // work either for SOAP generator case since generators use ModelDefinition.create to create property in the model + // dynamically, that execution path has strict validation where doesn't accept 'id: false' in a property. + // See https://github.com/strongloop/loopback-workspace/issues/486 for some more details. + var excludePropertyList = settings['excludeBaseProperties']; + // Remove properties that reverted by the subclass of the property from excludePropertyList + if (properties[p] === null || properties[p] === false || + (excludePropertyList != null && excludePropertyList.indexOf(p) != -1)) { // Hide the base property delete properties[p]; }