mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): Do not enable strict type validation by default for resource mapper (#13037)
This commit is contained in:
@@ -247,7 +247,8 @@ describe('validateValueAgainstSchema', () => {
|
||||
expect(typeof result).toEqual('number');
|
||||
});
|
||||
|
||||
describe('when the mode is in Fixed mode, and the node is a resource mapper', () => {
|
||||
describe('when validating a resource mapper value', () => {
|
||||
describe('when attemptToConvertTypes === true', () => {
|
||||
const nodeType = {
|
||||
description: {
|
||||
properties: [
|
||||
@@ -309,4 +310,93 @@ describe('validateValueAgainstSchema', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when attemptToConvertTypes is not set (=default)', () => {
|
||||
test('should correctly validate and convert types', () => {
|
||||
const nodeType = {
|
||||
description: {
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Columns',
|
||||
name: 'columns',
|
||||
type: 'resourceMapper',
|
||||
noDataExpression: true,
|
||||
default: {
|
||||
mappingMode: 'defineBelow',
|
||||
value: null,
|
||||
},
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['table.value', 'operation'],
|
||||
resourceMapper: {
|
||||
resourceMapperMethod: 'getMappingColumns',
|
||||
mode: 'upsert',
|
||||
fieldWords: {
|
||||
singular: 'column',
|
||||
plural: 'columns',
|
||||
},
|
||||
addAllFields: true,
|
||||
multiKeyMatch: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
} as unknown as INodeType;
|
||||
|
||||
const node: INode = {
|
||||
parameters: {
|
||||
columns: {
|
||||
mappingMode: 'defineBelow',
|
||||
value: {
|
||||
id: 2,
|
||||
count: '={{ $json.count }}',
|
||||
},
|
||||
matchingColumns: ['id'],
|
||||
schema: [
|
||||
{
|
||||
id: 'id',
|
||||
displayName: 'id',
|
||||
required: false,
|
||||
defaultMatch: true,
|
||||
display: true,
|
||||
type: 'number',
|
||||
canBeUsedToMatch: true,
|
||||
},
|
||||
{
|
||||
id: 'count',
|
||||
displayName: 'count',
|
||||
required: false,
|
||||
defaultMatch: false,
|
||||
display: true,
|
||||
type: 'number',
|
||||
canBeUsedToMatch: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
options: {},
|
||||
},
|
||||
id: '8d6cec63-8db1-440c-8966-4d6311ee69a9',
|
||||
name: 'add products to DB',
|
||||
type: 'n8n-nodes-base.postgres',
|
||||
typeVersion: 2.3,
|
||||
position: [420, 0],
|
||||
};
|
||||
|
||||
const value = {
|
||||
id: 2,
|
||||
count: '23',
|
||||
};
|
||||
|
||||
const parameterName = 'columns.value';
|
||||
|
||||
const result = validateValueAgainstSchema(node, nodeType, value, parameterName, 0, 0);
|
||||
|
||||
expect(result).toEqual({
|
||||
id: 2,
|
||||
count: 23,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -56,8 +56,8 @@ const validateResourceMapperValue = (
|
||||
if (schemaEntry?.type) {
|
||||
const validationResult = validateFieldType(key, resolvedValue, schemaEntry.type, {
|
||||
valueOptions: schemaEntry.options,
|
||||
strict: !resourceMapperField.attemptToConvertTypes,
|
||||
parseStrings: !!resourceMapperField.convertFieldsToString,
|
||||
strict: resourceMapperField.attemptToConvertTypes === false,
|
||||
parseStrings: Boolean(resourceMapperField.convertFieldsToString),
|
||||
});
|
||||
|
||||
if (!validationResult.valid) {
|
||||
|
||||
@@ -2722,8 +2722,8 @@ export type ResourceMapperValue = {
|
||||
value: { [key: string]: string | number | boolean | null } | null;
|
||||
matchingColumns: string[];
|
||||
schema: ResourceMapperField[];
|
||||
attemptToConvertTypes: boolean;
|
||||
convertFieldsToString: boolean;
|
||||
attemptToConvertTypes?: boolean;
|
||||
convertFieldsToString?: boolean;
|
||||
};
|
||||
|
||||
export type FilterOperatorType =
|
||||
|
||||
Reference in New Issue
Block a user