if (_.isUndefined(fn) && _.isFunction(priority)) { fn = priority; priority = 5;
var handlebarsPolicyHandler = function(props, context, flow) { var logger = flow.logger; logger.debug('ENTER handlebars policy'); if (_.isUndefined(props.source) || !_.isString(props.source)) { flow.fail({ name: 'HandlebarsError', value: 'Missing Handlebars template' }); return; } if (props.output && !_.isString(props.output)) { flow.fail({ name: 'HandlebarsError', value: 'Invalid output' }); return; } var output = 'message.body'; if (props.output) { output = props.output; } var templateFn; try { templateFn = Handlebars.compile(props.source); context.set(output, templateFn(context)); } catch (e) { flow.fail({ name: 'HandlebarsError', value: 'Invalid Handlebars template' }); return; } logger.debug('EXIT'); flow.proceed(); }
var javascriptPolicyHandler = function(props, context, flow) { var logger = flow.logger; logger.debug('ENTER javascript policy'); if (_.isUndefined(props.source) || !_.isString(props.source)) { flow.fail({ name: 'JavaScriptError', value: 'Invalid JavaScript code' }); return; } // need to wrap the code snippet into a function first try { var script = new vm.Script('(function() {' + props.source + '\n})()'); // use context as this to run the wrapped function // and also console for logging var origProto = Object.getPrototypeOf(context); var newProto = Object.create(origProto); newProto.console = consoleProxy(flow.logger); Object.setPrototypeOf(context, newProto); script.runInNewContext(context); Object.setPrototypeOf(context, origProto); logger.debug('EXIT'); flow.proceed(); } catch (e) { logger.debug('EXIT with an error:%s', e); if (e.name) { flow.fail(e); } else { flow.fail({ name: 'JavaScriptError', message: '' + e }); } } }
var inline = item['attribs']['inline']; var uriText = item['attribs'][uriType]; if (_.isUndefined(inline)) { if (uriText) { uriText = uriText.replace('\/\/' + config.domain, ''); var inline = item['attribs']['inline']; var uriText = item['attribs'][uriType]; if (_.isUndefined(inline)) { var failoverHref var failoverUriText
/* Schema Object Validators */ function validateArrayTypeItemsExistence (api, response, schema, path) { if (schema.type === 'array' && _.isUndefined(schema.items)) { response.errors.push({ code: 'OBJECT_MISSING_REQUIRED_PROPERTY', message: 'Missing required property: items', path: path }); } }
it('missing (non-array)', function (done) { var cOAIDoc = _.cloneDeep(tHelpers.oaiDoc); Sway.create({ definition: cOAIDoc }) .then(function (apiDef) { assert.ok(_.isUndefined(apiDef.getOperation('/pet/{petId}', 'get').getParameter('petId').getValue({ url: '/v2/pet' }).value)); }) .then(done, done); });
static parsePostParams(post={}) { let form, formData, sortedPost; if (post.embed && typeof post.embed !== 'string') { formData = post; post = _.omit(post,'embed'); } else if (!_(post).isEmpty()) { form = post; } sortedPost = _(post).omit(_.isUndefined).omit(_.isNull).sortBy((val, key) => key).toString(); return {form, formData, sortedPost}; }
validatePermission(data, permission, next) { if (_.get(data, 'server') !== this.uuid) { return next(null, false, 'uuidDoesNotMatch'); } if (!_.isUndefined(permission)) { if (_.includes(data.permissions, permission) || _.includes(data.permissions, 's:*')) { // Check Suspension Status return next(null, !this.isSuspended(), 'isSuspended'); } } return next(null, false, 'isUndefined'); }
get(key, defaultResponse) { let getObject; try { getObject = _.reduce(_.split(key, '.'), (o, i) => o[i], Cache.get('config')); } catch (ex) { _.noop(); } if (!_.isUndefined(getObject)) { return getObject; } return (!_.isUndefined(defaultResponse)) ? defaultResponse : undefined; }
function normalizeError (obj) { // Remove superfluous error details if (_.isUndefined(obj.schemaId)) { delete obj.schemaId; } if (obj.inner) { _.each(obj.inner, function (nObj) { normalizeError(nObj); }); } }
_.each(this.getPaths(), function (path) { if (_.isUndefined(operation)) { operation = path.getOperation(idOrPathOrReq); } });
function addReference (ref, ptr) { if (_.indexOf(references, ref) === -1) { if (_.isUndefined(references[ref])) { references[ref] = []; } // Add references to ancestors if (ref.indexOf('allOf') > -1) { addReference(ref.substring(0, ref.lastIndexOf('/allOf'))); } references[ref].push(ptr); } }
it('missing required value (with default)', function () { var paramValue = apiDefinition.getOperation('/pet/findByStatus', 'get').getParameter('status').getValue({ query: {} }); assert.deepEqual(paramValue.value, ['available']); assert.ok(paramValue.valid); assert.ok(_.isUndefined(paramValue.error)); });
// Build the schema from the schema-like parameter structure _.forEach(parameterSchemaProperties, function (name) { if (!_.isUndefined(paramDef[name])) { schema[name] = paramDef[name]; } });
it('provided required value', function () { var pet = { name: 'Sparky', photoUrls: [] }; var paramValue = apiDefinition.getOperation('/pet', 'post').getParameter('body').getValue({ body: pet }); assert.deepEqual(paramValue.value, pet); assert.ok(_.isUndefined(paramValue.error)); assert.ok(paramValue.valid); });