-
-
Notifications
You must be signed in to change notification settings - Fork 663
feat: pass zod schema to custom fetch response implementation #3226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a1770ad
515ea40
8877f73
84e0dbb
f66600f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -171,6 +171,7 @@ export interface NormalizedOverrideOutput { | |||||
| * @default false | ||||||
| */ | ||||||
| useNullForOptional?: boolean; | ||||||
| includeZodSchemaInArguments?: boolean; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| } | ||||||
|
|
||||||
| export interface NormalizedMutator { | ||||||
|
|
@@ -633,6 +634,7 @@ export interface OverrideOutput { | |||||
| * @default false | ||||||
| */ | ||||||
| useNullForOptional?: boolean; | ||||||
| includeZodSchemaInArguments?: boolean; | ||||||
| } | ||||||
|
|
||||||
| export interface JsDocOptions { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? ',' : ''} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}` : ''} | ||
| } | ||
| `; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const reviver = fetchReviver ? `, ${fetchReviver.name}` : ''; | ||
| const fetchResponseType = | ||
| override.fetch.forceSuccessResponse && hasSuccess | ||
| ? successName | ||
|
|
@@ -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, | ||
|
|
@@ -571,7 +581,7 @@ ${override.fetch.forceSuccessResponse && hasSuccess ? '' : `export type ${respon | |
| const ${formattedDeconstructor} = ${mutator.name}(); | ||
| return (${args}) => { | ||
| ${bodyForm} | ||
| return ${fetchExportName}(${fetchFnOptions}); | ||
| return ${fetchExportName}(${validateFetchFnOptions}); | ||
| } | ||
| `; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.