MCPcopy Create free account
hub / github.com/ShipSecAI/studio / isOptional

Function isOptional

packages/component-sdk/src/json-schema.ts:189–212  ·  view source on GitHub ↗

* Check if schema is optional

(schema: z.ZodTypeAny)

Source from the content-addressed store, hash-verified

187 * Check if schema is optional
188 */
189function isOptional(schema: z.ZodTypeAny): boolean {
190 let current = schema;
191
192 while (true) {
193 const def = (current as any)._def as ZodDef | undefined;
194
195 if (!def) break;
196
197 const typeName = getDefType(def);
198
199 if (typeName === 'optional') {
200 return true;
201 }
202
203 if (typeName === 'default' || typeName === 'nullable') {
204 current = def.innerType;
205 continue;
206 }
207
208 break;
209 }
210
211 return false;
212}

Callers 1

zodToJsonSchemaFunction · 0.70

Calls 1

getDefTypeFunction · 0.70

Tested by

no test coverage detected