File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -148,8 +148,8 @@ export function isStandardSchemaWithJSON(schema: unknown): schema is StandardSch
148148export function isZodRawShape ( obj : unknown ) : obj is Record < string , StandardSchemaV1 > {
149149 if ( typeof obj !== 'object' || obj === null ) return false ;
150150 if ( isStandardSchema ( obj ) ) return false ;
151- const values = Object . values ( obj ) ;
152- return values . length > 0 && values . every ( v => isStandardSchema ( v ) || ( typeof v === 'object' && v !== null && '_def' in v ) ) ;
151+ // [].every() is true, so an empty object is a valid raw shape (matches v1).
152+ return Object . values ( obj ) . every ( v => isStandardSchema ( v ) || ( typeof v === 'object' && v !== null && '_def' in v ) ) ;
153153}
154154
155155/**
Original file line number Diff line number Diff line change 11import * as z from 'zod/v4' ;
22
3- import { standardSchemaToJsonSchema } from '../../src/util/standardSchema.js' ;
3+ import { isZodRawShape , normalizeRawShapeSchema , standardSchemaToJsonSchema } from '../../src/util/standardSchema.js' ;
4+
5+ describe ( 'isZodRawShape' , ( ) => {
6+ test ( 'treats empty object as a raw shape (matches v1)' , ( ) => {
7+ expect ( isZodRawShape ( { } ) ) . toBe ( true ) ;
8+ } ) ;
9+ test ( 'detects raw shape with zod fields' , ( ) => {
10+ expect ( isZodRawShape ( { a : z . string ( ) } ) ) . toBe ( true ) ;
11+ } ) ;
12+ test ( 'rejects a Standard Schema instance' , ( ) => {
13+ expect ( isZodRawShape ( z . object ( { a : z . string ( ) } ) ) ) . toBe ( false ) ;
14+ } ) ;
15+ } ) ;
16+
17+ describe ( 'normalizeRawShapeSchema' , ( ) => {
18+ test ( 'wraps empty raw shape into z.object({})' , ( ) => {
19+ const wrapped = normalizeRawShapeSchema ( { } ) ;
20+ expect ( wrapped ) . toBeDefined ( ) ;
21+ expect ( standardSchemaToJsonSchema ( wrapped ! , 'input' ) . type ) . toBe ( 'object' ) ;
22+ } ) ;
23+ } ) ;
424
525describe ( 'standardSchemaToJsonSchema' , ( ) => {
626 test ( 'emits type:object for plain z.object schemas' , ( ) => {
You can’t perform that action at this time.
0 commit comments