From a8bab4317d4535eb5c583585775f2861eefbd1de Mon Sep 17 00:00:00 2001 From: nicosammito Date: Sun, 21 Jun 2026 02:19:00 +0200 Subject: [PATCH] fix: Schema select does not work on 1 union --- src/util/schema.util.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/util/schema.util.ts b/src/util/schema.util.ts index 625dfda..9ca86fe 100644 --- a/src/util/schema.util.ts +++ b/src/util/schema.util.ts @@ -174,6 +174,13 @@ export const getSchema = ( } } + // Check primitive literal union first (e.g., "a" | "b" | "c") or a single + // string/number literal (e.g., "GET"). A bare literal has only one allowed + // value, so it should still surface as a select rather than a free-form text/number input. + if (isPrimitiveLiteralUnion(parameterType) || isStringOrNumberLiteral(parameterType)) { + return {input: "select", ...combinedSuggestions}; + } + // Check individual primitive types if (isBoolean(parameterType)) { return {input: "boolean", ...combinedSuggestions}; @@ -185,11 +192,6 @@ export const getSchema = ( return {input: "text", ...combinedSuggestions}; } - // Check primitive literal union first (e.g., "a" | "b" | "c") - if (isPrimitiveLiteralUnion(parameterType)) { - return {input: "select", ...combinedSuggestions}; - } - // Check if type has call signatures (is callable/sub-flow) if (isSubFlow(parameterType)) { return {input: "sub-flow", ...combinedSuggestions}; @@ -334,6 +336,17 @@ function isPrimitive(type: ts.Type): boolean { return isString(type) || isNumber(type) || isBoolean(type); } +/** + * Checks if a type is a single string or number literal (e.g. "GET" or 42). + * Boolean literals are excluded so that types like `true` continue to render as a boolean input. + */ +function isStringOrNumberLiteral(type: ts.Type): boolean { + return ( + (type.flags & ts.TypeFlags.StringLiteral) !== 0 || + (type.flags & ts.TypeFlags.NumberLiteral) !== 0 + ); +} + /** * Checks if a type is a union of primitive types only. *