MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / isChoiceRequired

Function isChoiceRequired

lib/actionUtils.ts:3–29  ·  view source on GitHub ↗
(
  schema: OpenAPIV3_1.SchemaObject,
  parentRequired: boolean = true,
)

Source from the content-addressed store, hash-verified

1import { OpenAPIV3_1 } from "openapi-types";
2
3export function isChoiceRequired(
4 schema: OpenAPIV3_1.SchemaObject,
5 parentRequired: boolean = true,
6): boolean {
7 /** Determines whether there's a choice to be made by the AI for
8 * a parameter. There's no choice if it is required and has 1 enum
9 * value (or all nested children are like this) **/
10 if (!parentRequired) return true;
11 if (schema.type !== "object") {
12 return !(schema.enum && schema.enum.length === 1);
13 }
14
15 const requiredKeys = schema.required || [];
16
17 for (let key in schema.properties) {
18 const isKeyRequired = requiredKeys.includes(key);
19 const childSchema = schema.properties[key] as OpenAPIV3_1.SchemaObject;
20
21 // If any nested object requires choice, then choice is required.
22 if (isChoiceRequired(childSchema, isKeyRequired)) {
23 return true;
24 }
25 }
26
27 // If no choice required in any properties, then no choice required.
28 return false;
29}
30
31export function getFilledNoChoiceRequiredFields(
32 schema: OpenAPIV3_1.SchemaObject | undefined,

Callers 4

formatReqBodySchemaFunction · 0.90
formatReqBodySchemaFunction · 0.90
formatBodySchemaToTSFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected