Skip to content

Commit cf25f5c

Browse files
authored
Merge pull request #118 from code0-tech/feat/#112
Schema select does not work on 1 union
2 parents 8053f1d + a8bab43 commit cf25f5c

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/util/schema.util.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ export const getSchema = (
174174
}
175175
}
176176

177+
// Check primitive literal union first (e.g., "a" | "b" | "c") or a single
178+
// string/number literal (e.g., "GET"). A bare literal has only one allowed
179+
// value, so it should still surface as a select rather than a free-form text/number input.
180+
if (isPrimitiveLiteralUnion(parameterType) || isStringOrNumberLiteral(parameterType)) {
181+
return {input: "select", ...combinedSuggestions};
182+
}
183+
177184
// Check individual primitive types
178185
if (isBoolean(parameterType)) {
179186
return {input: "boolean", ...combinedSuggestions};
@@ -185,11 +192,6 @@ export const getSchema = (
185192
return {input: "text", ...combinedSuggestions};
186193
}
187194

188-
// Check primitive literal union first (e.g., "a" | "b" | "c")
189-
if (isPrimitiveLiteralUnion(parameterType)) {
190-
return {input: "select", ...combinedSuggestions};
191-
}
192-
193195
// Check if type has call signatures (is callable/sub-flow)
194196
if (isSubFlow(parameterType)) {
195197
return {input: "sub-flow", ...combinedSuggestions};
@@ -334,6 +336,17 @@ function isPrimitive(type: ts.Type): boolean {
334336
return isString(type) || isNumber(type) || isBoolean(type);
335337
}
336338

339+
/**
340+
* Checks if a type is a single string or number literal (e.g. "GET" or 42).
341+
* Boolean literals are excluded so that types like `true` continue to render as a boolean input.
342+
*/
343+
function isStringOrNumberLiteral(type: ts.Type): boolean {
344+
return (
345+
(type.flags & ts.TypeFlags.StringLiteral) !== 0 ||
346+
(type.flags & ts.TypeFlags.NumberLiteral) !== 0
347+
);
348+
}
349+
337350
/**
338351
* Checks if a type is a union of primitive types only.
339352
*

0 commit comments

Comments
 (0)