@@ -45,14 +45,6 @@ const FETCH_DEPENDENCIES: GeneratorDependency[] = [
4545
4646export const getFetchDependencies = ( ) => FETCH_DEPENDENCIES ;
4747
48- const PRIMITIVE_TYPES = new Set ( [
49- 'string' ,
50- 'number' ,
51- 'boolean' ,
52- 'void' ,
53- 'unknown' ,
54- ] ) ;
55-
5648export const generateRequestFunction = (
5749 {
5850 queryParams,
169161 ) ;
170162
171163 const responseType = response . definition . success ;
172- const isPrimitiveType = PRIMITIVE_TYPES . has ( responseType ) ;
164+
165+ const isPrimitiveType = [
166+ 'string' ,
167+ 'number' ,
168+ 'boolean' ,
169+ 'void' ,
170+ 'unknown' ,
171+ ] . includes ( responseType ) ;
173172 const hasSchema = response . imports . some ( ( imp ) => imp . name === responseType ) ;
174173
175174 const isValidateResponse =
204203 )
205204 . map ( ( r ) => {
206205 const name = `${ responseTypeName } ${ pascal ( r . key ) } ${ 'suffix' in r ? r . suffix : '' } ` ;
207-
208- const hasValidZodSchema = r . value && ! PRIMITIVE_TYPES . has ( r . value ) ;
209- const dataType =
210- override . fetch . useZodSchemaResponse && hasValidZodSchema
211- ? `zod.infer<typeof ${ r . value } >`
212- : r . value || 'unknown' ;
206+ const dataType = r . value || 'unknown' ;
213207
214208 return {
215209 name,
@@ -413,57 +407,24 @@ export const fetchResponseTypeName = (
413407export const generateClient : ClientBuilder = (
414408 verbOptions ,
415409 options ,
416- outputClient ,
410+ _outputClient ,
417411 output ,
418412) => {
419413 const imports = generateVerbImports ( verbOptions ) ;
420414 const functionImplementation = generateRequestFunction ( verbOptions , options ) ;
421415
422- const isZodSchemaImportsRequired =
423- verbOptions . override . fetch . useZodSchemaResponse ||
424- verbOptions . override . fetch . runtimeValidation ;
425-
426- const responseImports = isZodSchemaImportsRequired
427- ? [
428- ...verbOptions . response . types . success ,
429- ...verbOptions . response . types . errors ,
430- ] . flatMap ( ( response ) =>
431- response . imports . map ( ( imp ) => ( {
432- name : imp . name ,
433- schemaName : imp . name ,
434- isZodSchema : true ,
435- values : true ,
436- } ) ) ,
437- )
438- : [ ] ;
439-
440- const requestImports = isZodSchemaImportsRequired
441- ? [
442- ...verbOptions . body . imports ,
443- ...( verbOptions . queryParams
444- ? [ { name : `${ pascal ( verbOptions . operationName ) } QueryParams` } ]
445- : [ ] ) ,
446- ...( verbOptions . headers
447- ? [ { name : `${ pascal ( verbOptions . operationName ) } Header` } ]
448- : [ ] ) ,
449- ] . map ( ( imp ) => ( {
450- name : imp . name ,
451- schemaName : imp . name ,
452- isZodSchema : true ,
453- values : true ,
454- } ) )
455- : [ ] ;
456-
457- const zodSchemaImports = [ ...responseImports , ...requestImports ] ;
416+ const isZodSchema =
417+ isObject ( output ?. schemas ) && output . schemas . type === 'zod' ;
458418
459- const zodSchemaNames = new Set ( zodSchemaImports . map ( ( imp ) => imp . name ) ) ;
460- const filteredImports = imports . filter (
461- ( imp ) => ! zodSchemaNames . has ( imp . name ) ,
462- ) ;
419+ const generateImports = imports . map ( ( imp ) => ( {
420+ ...imp ,
421+ isZodSchema : isZodSchema ,
422+ values : isZodSchema ? true : imp . values ,
423+ } ) ) ;
463424
464425 return {
465426 implementation : `${ functionImplementation } \n` ,
466- imports : [ ... filteredImports , ... zodSchemaImports ] ,
427+ imports : generateImports ,
467428 } ;
468429} ;
469430
0 commit comments