Skip to content

Commit

Permalink
[backend] check complex object even if not mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
lndrtrbn committed Feb 27, 2024
1 parent e242569 commit 9384a8c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions opencti-platform/opencti-graphql/src/schema/schema-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,16 @@ const validateInputAgainstSchema = (input: any, schemaDef: AttributeDefinition)
}

if (isNonFlatObjectAttributeMapping(schemaDef)) {
// check 'multiple' constraint
if (isMandatory) {
if (schemaDef.multiple && !Array.isArray(input)) {
throw FunctionalError(`Validation against schema failed on attribute [${schemaDef.name}]: value must be an array`, { value: input });
}
if (!schemaDef.multiple && (Array.isArray(input) || !R.is(Object, input))) {
throw FunctionalError(`Validation against schema failed on attribute [${schemaDef.name}]: value must be an object`, { value: input });
}
}
if (!isMandatory && R.isNil(input)) {
return; // nothing to check (happens on 'remove' operation for instance
}
// check 'multiple' constraint
if (schemaDef.multiple && !Array.isArray(input)) {
throw FunctionalError(`Validation against schema failed on attribute [${schemaDef.name}]: value must be an array`, { value: input });
}
if (!schemaDef.multiple && (Array.isArray(input) || !R.is(Object, input))) {
throw FunctionalError(`Validation against schema failed on attribute [${schemaDef.name}]: value must be an object`, { value: input });
}

const inputValues = Array.isArray(input) ? input : [input];
inputValues.forEach((value) => {
Expand Down

0 comments on commit 9384a8c

Please sign in to comment.