fix(Code Tool Node): Fix Input Schema Parameter not hiding correctly (#13245)

This commit is contained in:
Charlie Kolb
2025-02-17 11:31:29 +01:00
committed by GitHub
parent b4380d0508
commit 8e15ebf833
2 changed files with 22 additions and 8 deletions

View File

@@ -15,7 +15,11 @@ import type {
} from 'n8n-workflow'; } from 'n8n-workflow';
import { jsonParse, NodeConnectionType, NodeOperationError } from 'n8n-workflow'; import { jsonParse, NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import { inputSchemaField, jsonSchemaExampleField, schemaTypeField } from '@utils/descriptions'; import {
buildInputSchemaField,
buildJsonSchemaExampleField,
schemaTypeField,
} from '@utils/descriptions';
import { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing'; import { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing';
import { getConnectionHintNoticeField } from '@utils/sharedFields'; import { getConnectionHintNoticeField } from '@utils/sharedFields';
@@ -168,8 +172,8 @@ export class ToolCode implements INodeType {
default: false, default: false,
}, },
{ ...schemaTypeField, displayOptions: { show: { specifyInputSchema: [true] } } }, { ...schemaTypeField, displayOptions: { show: { specifyInputSchema: [true] } } },
jsonSchemaExampleField, buildJsonSchemaExampleField({ showExtraProps: { specifyInputSchema: [true] } }),
inputSchemaField, buildInputSchemaField({ showExtraProps: { specifyInputSchema: [true] } }),
], ],
}; };

View File

@@ -1,4 +1,4 @@
import type { INodeProperties } from 'n8n-workflow'; import type { DisplayCondition, INodeProperties, NodeParameterValue } from 'n8n-workflow';
export const schemaTypeField: INodeProperties = { export const schemaTypeField: INodeProperties = {
displayName: 'Schema Type', displayName: 'Schema Type',
@@ -21,7 +21,9 @@ export const schemaTypeField: INodeProperties = {
description: 'How to specify the schema for the function', description: 'How to specify the schema for the function',
}; };
export const jsonSchemaExampleField: INodeProperties = { export const buildJsonSchemaExampleField = (props?: {
showExtraProps?: Record<string, Array<NodeParameterValue | DisplayCondition> | undefined>;
}): INodeProperties => ({
displayName: 'JSON Example', displayName: 'JSON Example',
name: 'jsonSchemaExample', name: 'jsonSchemaExample',
type: 'json', type: 'json',
@@ -34,13 +36,18 @@ export const jsonSchemaExampleField: INodeProperties = {
}, },
displayOptions: { displayOptions: {
show: { show: {
...props?.showExtraProps,
schemaType: ['fromJson'], schemaType: ['fromJson'],
}, },
}, },
description: 'Example JSON object to use to generate the schema', description: 'Example JSON object to use to generate the schema',
}; });
export const inputSchemaField: INodeProperties = { export const jsonSchemaExampleField = buildJsonSchemaExampleField();
export const buildInputSchemaField = (props?: {
showExtraProps?: Record<string, Array<NodeParameterValue | DisplayCondition> | undefined>;
}): INodeProperties => ({
displayName: 'Input Schema', displayName: 'Input Schema',
name: 'inputSchema', name: 'inputSchema',
type: 'json', type: 'json',
@@ -59,11 +66,14 @@ export const inputSchemaField: INodeProperties = {
}, },
displayOptions: { displayOptions: {
show: { show: {
...props?.showExtraProps,
schemaType: ['manual'], schemaType: ['manual'],
}, },
}, },
description: 'Schema to use for the function', description: 'Schema to use for the function',
}; });
export const inputSchemaField = buildInputSchemaField();
export const promptTypeOptions: INodeProperties = { export const promptTypeOptions: INodeProperties = {
displayName: 'Source for Prompt (User Message)', displayName: 'Source for Prompt (User Message)',