@@ -542,25 +542,86 @@ const getHttpResourceResponseImports = (
542542 } ) ;
543543} ;
544544
545+ const getParseSchemaName = (
546+ response : {
547+ readonly imports : readonly { name : string ; isZodSchema ?: boolean } [ ] ;
548+ readonly definition : { readonly success ?: string } ;
549+ } ,
550+ factory : HttpResourceFactoryName ,
551+ output : NormalizedOutputOptions ,
552+ responseTypeOverride ?: string ,
553+ ) : string | undefined => {
554+ if ( factory !== 'httpResource' ) return undefined ;
555+
556+ // Explicit isZodSchema flag on imports (forward-compatible)
557+ const zodSchema = response . imports . find ( ( imp ) => imp . isZodSchema ) ;
558+ if ( zodSchema ) return zodSchema . name ;
559+
560+ // Check if runtime validation is disabled
561+ if ( ! output . override . angular . runtimeValidation ) return undefined ;
562+
563+ // Auto-detect: when schemas.type === 'zod', use the response type as the schema name
564+ if ( ! isZodSchemaOutput ( output ) ) return undefined ;
565+
566+ const responseType = responseTypeOverride ?? response . definition . success ;
567+ if ( ! responseType ) return undefined ;
568+ if ( isPrimitiveType ( responseType ) ) return undefined ;
569+
570+ // Verify a matching import exists (the response type name resolves to a zod schema)
571+ const hasMatchingImport = response . imports . some (
572+ ( imp ) => imp . name === responseType ,
573+ ) ;
574+ if ( ! hasMatchingImport ) return undefined ;
575+
576+ return responseType ;
577+ } ;
578+
579+ const getHttpResourceZodParsedImportNames = (
580+ response : GeneratorVerbOptions [ 'response' ] ,
581+ output : NormalizedOutputOptions ,
582+ ) : Set < string > => {
583+ const names = new Set < string > ( ) ;
584+
585+ for ( const successType of response . types . success ) {
586+ const schemaName = getParseSchemaName (
587+ response ,
588+ getHttpResourceFactory (
589+ response ,
590+ successType . contentType ,
591+ successType . value ,
592+ ) ,
593+ output ,
594+ successType . value ,
595+ ) ;
596+
597+ if ( schemaName ) {
598+ names . add ( schemaName ) ;
599+ }
600+ }
601+
602+ return names ;
603+ } ;
604+
545605const getHttpResourceVerbImports = (
546606 verbOptions : GeneratorVerbOptions ,
547607 output : NormalizedOutputOptions ,
548608) : GeneratorImport [ ] => {
549609 const { response, body, queryParams, props, headers, params } = verbOptions ;
550- const responseImports = isZodSchemaOutput ( output )
551- ? [
552- ...getHttpResourceResponseImports ( response ) . map ( ( imp ) => ( {
553- ...imp ,
554- values : true ,
555- } ) ) ,
556- ...getHttpResourceResponseImports ( response )
557- . filter ( ( imp ) => ! isPrimitiveType ( imp . name ) )
558- . map ( ( imp ) => ( { name : getSchemaOutputTypeRef ( imp . name ) } ) ) ,
559- ]
560- : getHttpResourceResponseImports ( response ) ;
610+ const responseImports = getHttpResourceResponseImports ( response ) ;
611+ const parsedZodImportNames = isZodSchemaOutput ( output )
612+ ? getHttpResourceZodParsedImportNames ( response , output )
613+ : new Set < string > ( ) ;
614+ const parsedZodImports = responseImports . filter ( ( imp ) =>
615+ parsedZodImportNames . has ( imp . name ) ,
616+ ) ;
561617
562618 return [
563- ...responseImports ,
619+ ...responseImports . map ( ( imp ) =>
620+ parsedZodImportNames . has ( imp . name ) ? { ...imp , values : true } : imp ,
621+ ) ,
622+ ...parsedZodImports
623+ . filter ( ( imp ) => ! isPrimitiveType ( imp . name ) )
624+ . map ( ( imp ) => ( { name : getSchemaOutputTypeRef ( imp . name ) } ) ) ,
564625 ...body . imports ,
565626 ...props . flatMap ( ( prop ) =>
566627 prop . type === GetterPropType . NAMED_PATH_PARAMS
@@ -583,29 +644,14 @@ const getParseExpression = (
583644 output : NormalizedOutputOptions ,
584645 responseTypeOverride ?: string ,
585646) : string | undefined => {
586- if ( factory !== 'httpResource' ) return undefined ;
587-
588- // Explicit isZodSchema flag on imports (forward-compatible)
589- const zodSchema = response . imports . find ( ( imp ) => imp . isZodSchema ) ;
590- if ( zodSchema ) return `${ zodSchema . name } .parse` ;
591-
592- // Check if runtime validation is disabled
593- if ( ! output . override . angular . runtimeValidation ) return undefined ;
594-
595- // Auto-detect: when schemas.type === 'zod', use the response type as the schema name
596- if ( ! isZodSchemaOutput ( output ) ) return undefined ;
597-
598- const responseType = responseTypeOverride ?? response . definition . success ;
599- if ( ! responseType ) return undefined ;
600- if ( isPrimitiveType ( responseType ) ) return undefined ;
601-
602- // Verify a matching import exists (the response type name resolves to a zod schema)
603- const hasMatchingImport = response . imports . some (
604- ( imp ) => imp . name === responseType ,
647+ const schemaName = getParseSchemaName (
648+ response ,
649+ factory ,
650+ output ,
651+ responseTypeOverride ,
605652 ) ;
606- if ( ! hasMatchingImport ) return undefined ;
607653
608- return `${ responseType } .parse` ;
654+ return schemaName ? `${ schemaName } .parse` : undefined ;
609655} ;
610656
611657/**
0 commit comments