@@ -11,7 +11,6 @@ import {
1111 getZodExtendedImportPath ,
1212} from "../utils/generate/generate.utils" ;
1313import { getHbsTemplateDelegate } from "../utils/hbs/hbs-template.utils" ;
14- import { isString } from "../utils/string.utils" ;
1514import { isNamedZodSchema } from "../utils/zod-schema.utils" ;
1615
1716export function generateEndpoints ( { resolver, data, tag = "" } : GenerateTypeParams ) {
@@ -25,32 +24,34 @@ export function generateEndpoints({ resolver, data, tag = "" }: GenerateTypePara
2524 from : getAppRestClientImportPath ( resolver . options ) ,
2625 } ;
2726
28- const hasZodExtendedImport = endpoints . some ( ( endpoint ) =>
29- endpoint . parameters . some ( ( param ) => param . parameterSortingEnumSchemaName ) ,
30- ) ;
31- const zodExtendedImport : Import = {
32- bindings : [ ZOD_EXTENDED . name ] ,
33- from : getZodExtendedImportPath ( resolver . options ) ,
34- } ;
35-
3627 const hasAxiosRequestConfig = resolver . options . axiosRequestConfig ;
3728 const hasAxiosImport = hasAxiosRequestConfig ;
3829 const axiosImport : Import = {
3930 bindings : hasAxiosRequestConfig ? [ AXIOS_REQUEST_CONFIG_TYPE ] : [ ] ,
4031 from : AXIOS_IMPORT . from ,
4132 } ;
4233
43- const endpointResponseSchemas = endpoints . map ( ( endpoint ) => endpoint . response ) ;
44- const hasZodImport = endpointResponseSchemas . some ( ( response ) => ! isNamedZodSchema ( response ) ) ;
34+ const generateParse = resolver . options . parseRequestParams ;
4535
4636 const endpointParams = endpoints . reduce ( ( prev , curr ) => [ ...prev , ...curr . parameters ] , [ ] as EndpointParameter [ ] ) ;
37+ const endpointParamsParseSchemas = endpointParams
38+ . filter ( ( param ) => ! [ "Path" , "Header" ] . includes ( param . type ) )
39+ . map ( ( param ) => param . parameterSortingEnumSchemaName ?? param . zodSchema ) ;
40+ const endpointResponseSchemas = endpoints . map ( ( endpoint ) => endpoint . response ) ;
41+ const zodSchemas = getUniqueArray ( [ ...endpointResponseSchemas , ...( generateParse ? endpointParamsParseSchemas : [ ] ) ] ) ;
42+
43+ const hasZodImport = zodSchemas . some ( ( schema ) => ! isNamedZodSchema ( schema ) ) ;
44+
45+ const hasZodExtendedImport = resolver . options . parseRequestParams && endpointParamsParseSchemas . length > 0 ;
46+ const zodExtendedImport : Import = {
47+ bindings : [ ZOD_EXTENDED . name ] ,
48+ from : getZodExtendedImportPath ( resolver . options ) ,
49+ } ;
50+
4751 const modelsImports = getModelsImports ( {
4852 resolver,
4953 tag,
50- zodSchemas : getUniqueArray ( [
51- ...endpointResponseSchemas . filter ( isNamedZodSchema ) ,
52- ...endpointParams . map ( ( param ) => param . parameterSortingEnumSchemaName ) . filter ( isString ) ,
53- ] ) ,
54+ zodSchemas : zodSchemas . filter ( isNamedZodSchema ) ,
5455 zodSchemasAsTypes : getUniqueArray ( endpointParams . map ( ( param ) => param . zodSchema ) . filter ( isNamedZodSchema ) ) ,
5556 } ) ;
5657
@@ -72,5 +73,6 @@ export function generateEndpoints({ resolver, data, tag = "" }: GenerateTypePara
7273 axiosRequestConfigName : AXIOS_REQUEST_CONFIG_NAME ,
7374 axiosRequestConfigType : AXIOS_REQUEST_CONFIG_TYPE ,
7475 endpoints,
76+ generateParse,
7577 } ) ;
7678}
0 commit comments