@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 06:00 UTC

next
ts 24 lines 929 Bytes
Raw
1 import { parseSchema } from './parse-schema';
2 import type { ParseContext } from '../context';
3 import type { JsonSchemaObject } from '../types';
4 import { omit } from '../utils/omit';
5
6 /**
7 * For compatibility with open api 3.0 nullable
8 */
9 export const parseNullable = <S>(
10 jsonSchema: JsonSchemaObject & { nullable: true },
11 ctx: ParseContext<S>
12 ): S => {
13 // If the schema has a null default, we need to handle it specially
14 // Remove the default from the base schema to prevent it from being applied to non-null types
15 const hasNullDefault = jsonSchema.default === null;
16 const baseSchema = hasNullDefault
17 ? omit(omit(jsonSchema, 'nullable'), 'default')
18 : omit(jsonSchema, 'nullable');
19
20 const zodSchema = ctx.backend.nullable(parseSchema(baseSchema, ctx, true));
21
22 // Apply the null default at the nullable level if it exists
23 return hasNullDefault ? ctx.backend.withDefault(zodSchema, null) : zodSchema;
24 };