Files
twenty/packages/twenty-shared/src/logic-function/json-schema-to-input-schema.ts
T
Abdul RahmanandGitHub 1adb59f7f8 Support optional labels on logic-function input schema fields (#20471)
Adds an optional label field to logic-function input schema properties
(InputSchemaProperty and InputJsonSchema). When set, the workflow
builder renders the label in place of the raw property key for both leaf
inputs and nested sections; when unset, it falls back to the key.
jsonSchemaToInputSchema propagates the label so app authors can declare
it in their JSON schema. Payload paths, the variable picker, and saved
workflow inputs continue to use the property key — labels are
display-only.
2026-05-12 06:40:10 +00:00

69 lines
1.8 KiB
TypeScript

import { type InputJsonSchema } from '@/logic-function/input-json-schema.type';
import {
type InputSchema,
type InputSchemaProperty,
} from '@/workflow/types/InputSchema';
import { isNonEmptyString } from '@sniptt/guards';
const convertProperty = (jsonSchema: InputJsonSchema): InputSchemaProperty => {
const property: InputSchemaProperty = { type: 'unknown' };
switch (jsonSchema.type) {
case 'string':
property.type = 'string';
break;
case 'number':
case 'integer':
property.type = 'number';
break;
case 'boolean':
property.type = 'boolean';
break;
case 'array':
property.type = 'array';
if (jsonSchema.items) {
property.items = convertProperty(jsonSchema.items);
}
break;
case 'object':
property.type = 'object';
if (jsonSchema.properties) {
property.properties = Object.fromEntries(
Object.entries(jsonSchema.properties).map(([key, value]) => [
key,
convertProperty(value),
]),
);
}
break;
case 'null':
default:
property.type = 'unknown';
}
if (Array.isArray(jsonSchema.enum)) {
property.enum = jsonSchema.enum.filter(
(value): value is string => typeof value === 'string',
);
}
if (jsonSchema.multiline === true) {
property.multiline = true;
}
if (isNonEmptyString(jsonSchema.label)) {
property.label = jsonSchema.label;
}
return property;
};
// Wraps in a single-element array because Twenty's InputSchema represents
// the parameter list of a function -- logic functions take a single params
// object, hence a one-element array containing it.
export const jsonSchemaToInputSchema = (
jsonSchema: InputJsonSchema,
): InputSchema => {
return [convertProperty(jsonSchema)];
};