Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
errors.push(
new jsonschema.ValidationError(
`must match a "key" from a search (options: ${searchKeys})`,
searchOrCreateDef,
'/SearchOrCreateSchema',
`instance.searchOrCreates.${key}.search`,
'invalidKey',
'search'
)
);
}
// Confirm searchOrCreate.create matches a creates.key
if (!definition.creates[createKey]) {
errors.push(
new jsonschema.ValidationError(
`must match a "key" from a create (options: ${createKeys})`,
searchOrCreateDef,
'/SearchOrCreateSchema',
`instance.searchOrCreates.${key}.create`,
'invalidKey',
'create'
)
);
}
});
errors.push(
new jsonschema.ValidationError(
`must match a "key" from a search (options: ${searchKeys})`,
searchOrCreateDef,
'/SearchOrCreateSchema',
`instance.searchOrCreates.${key}.key`,
'invalidKey',
'key'
)
);
}
// Confirm searchOrCreate.search matches a searches.key
if (!definition.searches[searchKey]) {
errors.push(
new jsonschema.ValidationError(
`must match a "key" from a search (options: ${searchKeys})`,
searchOrCreateDef,
'/SearchOrCreateSchema',
`instance.searchOrCreates.${key}.search`,
'invalidKey',
'search'
)
);
}
// Confirm searchOrCreate.create matches a creates.key
if (!definition.creates[createKey]) {
errors.push(
new jsonschema.ValidationError(
`must match a "key" from a create (options: ${createKeys})`,
searchOrCreateDef,
definitions = RESOURCE_METHODS.map(method => definition[method]).filter(
Boolean
);
// allow method definitions to inherit the sample
if (definition.sample) {
definitions.forEach(methodDefinition => {
if (methodDefinition.operation && !methodDefinition.operation.sample) {
methodDefinition.operation.sample = definition.sample;
}
});
}
if (!definitions.length) {
return [
new jsonschema.ValidationError(
'expected at least one resource operation',
definition,
definition.id
)
];
}
} else {
definitions = [definition];
}
return definitions.map(check).filter(Boolean);
};
_.each(definition.searchOrCreates, (searchOrCreateDef, key) => {
const searchOrCreateKey = searchOrCreateDef.key;
const searchKey = searchOrCreateDef.search;
const createKey = searchOrCreateDef.create;
// Confirm searchOrCreate.key matches a searches.key (current Zapier editor limitation)
if (!definition.searches[searchOrCreateKey]) {
errors.push(
new jsonschema.ValidationError(
`must match a "key" from a search (options: ${searchKeys})`,
searchOrCreateDef,
'/SearchOrCreateSchema',
`instance.searchOrCreates.${key}.key`,
'invalidKey',
'key'
)
);
}
// Confirm searchOrCreate.search matches a searches.key
if (!definition.searches[searchKey]) {
errors.push(
new jsonschema.ValidationError(
`must match a "key" from a search (options: ${searchKeys})`,
searchOrCreateDef,
_.each(group, (action, key) => {
if (action.key !== key) {
errors.push(
new jsonschema.ValidationError(
`must have a matching top-level key (found "${key}" and "${
action.key
}")`,
action,
`/${_.capitalize(actionType)}Schema`,
`instance.${key}.key`,
'invalid',
'key'
)
);
}
});
}
inputField,
'/FieldSchema',
`instance.${path}.inputFields[${index}].children`,
'empty',
'inputFields'
)
);
} else {
const hasDeeplyNestedChildren = _.some(
inputField.children,
child => child.children
);
if (hasDeeplyNestedChildren) {
errors.push(
new jsonschema.ValidationError(
'must not contain deeply nested child fields. One level max.',
inputField,
'/FieldSchema',
`instance.${path}.inputFields[${index}]`,
'deepNesting',
'inputFields'
)
);
}
}
}
});
_.each(inputFields, (inputField, index) => {
if (inputField.children) {
if (inputField.children.length === 0) {
errors.push(
new jsonschema.ValidationError(
'must not be empty.',
inputField,
'/FieldSchema',
`instance.${path}.inputFields[${index}].children`,
'empty',
'inputFields'
)
);
} else {
const hasDeeplyNestedChildren = _.some(
inputField.children,
child => child.children
);
if (hasDeeplyNestedChildren) {
errors.push(
_.each(incompatibleFields, ([firstField, secondField]) => {
if (_.has(inputField, firstField) && _.has(inputField, secondField)) {
errors.push(
new jsonschema.ValidationError(
`must not contain ${firstField} and ${secondField}, as they're mutually exclusive.`,
inputField,
'/FieldSchema',
`instance.${path}.inputFields[${index}]`,
'invalid',
'inputFields'
)
);
}
});
});
const check = definition => {
if (!definition.operation || _.get(definition, 'display.hidden')) {
return null;
}
const samples = _.get(definition, 'operation.sample', {});
return !_.isEmpty(samples)
? null
: new jsonschema.ValidationError(
'requires "sample", because it\'s not hidden',
definition,
definition.id
);
};