Hello dear Forum !
I am quite new to n8n and impressed of its possibilities.
I have a question regarding a code-tool-node and hope you can help me.
I define a sample javascript code to either add 2 or 3 numbers, dependent on an input variable (Berechnungsart). This is just for test purpose and has no real sense.
What i want to achieve is, to define the json input schema in that way, that dependent on the choosen calculation type (add_2_numbers or add_3_numbers) the required input values adapt to the choosen calculation type.
In this example:
Berechnungsart = add_2_numbers : a,b must be required.
Berechnungsart = add_3_numbers, a,b,c must be required.
I try to define the schema in this way without success (using if);
{
"type": "object",
"properties": {
"berechnungsart": {
"type": "string",
"enum": ["add_2_numbers", "add_3_numbers"],
"description": "Definiert, ob zwei oder drei Zahlen addiert werden sollen."
},
"a": {
"type": "number",
"description": "Die erste Zahl, die addiert werden soll."
},
"b": {
"type": "number",
"description": "Die zweite Zahl, die addiert werden soll."
},
"c": {
"type": "number",
"description": "Die dritte Zahl, die addiert werden soll."
}
},
"required": ["berechnungsart"],
"allOf": [
{
"if": {
"properties": { "berechnungsart": { "const": "add_2_numbers" } }
},
"then": {
"required": ["a", "b"]
}
},
{
"if": {
"properties": { "berechnungsart": { "const": "add_3_numbers" } }
},
"then": {
"required": ["a", "b", "c"]
}
}
]
}
this gives me the error:
Error in sub-node ‘OpenAI Chat Model‘
Invalid schema for function ‘Addierer’: schema must be a JSON Schema of ‘type: “object”’, got ‘type: “None”’.
Open node
How can i make certain input variables “required” denpendend on other inputvariables with using the json schema definition ?
Information on your n8n setup
- **n8n version:1.88.0
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- **Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
- **Operating system: WIN 10