Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/_vendor/zod-to-json-schema/parseDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const selectParser = (
case ZodFirstPartyTypeKind.ZodDefault:
return parseDefaultDef(def, refs);
case ZodFirstPartyTypeKind.ZodBranded:
return parseBrandedDef(def, refs);
return parseBrandedDef(def, refs, forceResolution);
case ZodFirstPartyTypeKind.ZodReadonly:
return parseReadonlyDef(def, refs);
case ZodFirstPartyTypeKind.ZodCatch:
Expand Down
4 changes: 2 additions & 2 deletions src/_vendor/zod-to-json-schema/parsers/branded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { ZodBrandedDef } from 'zod/v3';
import { parseDef } from '../parseDef';
import { Refs } from '../Refs';

export function parseBrandedDef(_def: ZodBrandedDef<any>, refs: Refs) {
return parseDef(_def.type._def, refs);
export function parseBrandedDef(_def: ZodBrandedDef<any>, refs: Refs, forceResolution = false) {
return parseDef(_def.type._def, refs, forceResolution);
}
28 changes: 27 additions & 1 deletion tests/helpers/zod.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { zodResponseFormat } from 'openai/helpers/zod';
import { zodResponseFormat, zodTextFormat } from 'openai/helpers/zod';
import { z as zv3 } from 'zod/v3';
import { z as zv4 } from 'zod/v4';

Expand Down Expand Up @@ -359,4 +359,30 @@ describe.each([

expect(consoleSpy).toHaveBeenCalledTimes(0);
});

it('does not emit circular refs for branded zodTextFormat array items', () => {
if (version !== 'v3') {
return;
}

const BlockIdSchema = z.string().brand<'SlideId'>();
const SlidePlanSchema = z.object({
slides: z.array(
z.object({
subtitle: z.array(BlockIdSchema).nullable(),
content: z.array(BlockIdSchema).min(1),
}),
),
});

const jsonSchema = zodTextFormat(SlidePlanSchema, 'slidePlan').schema as {
definitions?: Record<string, unknown>;
};

expect(
jsonSchema.definitions?.['slidePlan_properties_slides_items_properties_subtitle_anyOf_0_items'],
).toEqual({
type: 'string',
});
});
});