Skip to content
Draft
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: 2 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export interface NormalizedOverrideOutput {
* @default false
*/
useNullForOptional?: boolean;
includeZodSchemaInArguments?: boolean;
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please normalize and specify the initial value for the boolean.

https://github.com/orval-labs/orval/blob/master/packages/orval/src/utils/options.ts

Suggested change
includeZodSchemaInArguments?: boolean;
includeZodSchemaInArguments: boolean;

}

export interface NormalizedMutator {
Expand Down Expand Up @@ -633,6 +634,7 @@ export interface OverrideOutput {
* @default false
*/
useNullForOptional?: boolean;
includeZodSchemaInArguments?: boolean;
}

export interface JsDocOptions {
Expand Down
20 changes: 15 additions & 5 deletions packages/fetch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,17 +435,27 @@ ${override.fetch.forceSuccessResponse && hasSuccess ? '' : `export type ${respon
? `body: ${requestBodyParams}`
: `body: JSON.stringify(${requestBodyParams})`
: '';
const fetchFnOptions = `${getUrlFnName}(${getUrlFnProperties}),
const rawFetchFnOptions = `${getUrlFnName}(${getUrlFnProperties}),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think it was necessary to relinquish the variable name and rearrange the values ​​here.

{${globalFetchOptions ? '\n' : ''} ${globalFetchOptions}
${isRequestOptions ? '...options,' : ''}
${fetchMethodOption}${fetchHeadersOption ? ',' : ''}
${fetchHeadersOption}${fetchBodyOption ? ',' : ''}
${fetchBodyOption}
${fetchBodyOption}`;
const fetchFnOptions = `${rawFetchFnOptions}
}
`;
const reviver = fetchReviver ? `, ${fetchReviver.name}` : '';
const schemaValueRef =
responseType === 'Error' ? 'ErrorSchema' : responseType;
const includeZodSchema =
context.output.override.includeZodSchemaInArguments &&
schemaValueRef !== 'void' &&
typeof context.output.schemas === 'object' &&
context.output.schemas.type === 'zod';
const validateFetchFnOptions = `${rawFetchFnOptions}${includeZodSchema ? ',' : ''}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best to include this process within the function that creates the fetch options.

${includeZodSchema ? `schema: ${schemaValueRef}` : ''}
}
`;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const reviver = fetchReviver ? `, ${fetchReviver.name}` : '';
const fetchResponseType =
override.fetch.forceSuccessResponse && hasSuccess
? successName
Expand Down Expand Up @@ -549,7 +559,7 @@ ${override.fetch.forceSuccessResponse && hasSuccess ? '' : `export type ${respon
: 'return data'
}
`;
let customFetchResponseImplementation = `return ${mutator?.name}<${fetchResponseType}>(${fetchFnOptions});`;
let customFetchResponseImplementation = `return ${mutator?.name}<${fetchResponseType}>(${validateFetchFnOptions});`;

const bodyForm = generateFormDataAndUrlEncodedFunction({
formData,
Expand All @@ -571,7 +581,7 @@ ${override.fetch.forceSuccessResponse && hasSuccess ? '' : `export type ${respon
const ${formattedDeconstructor} = ${mutator.name}();
return (${args}) => {
${bodyForm}
return ${fetchExportName}(${fetchFnOptions});
return ${fetchExportName}(${validateFetchFnOptions});
}
`;
}
Expand Down
Loading