Skip to content
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

fix: swr mutation fetcher - name param __ in case of no body arg #1263

Merged
Merged
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
8 changes: 7 additions & 1 deletion packages/swr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,15 @@ export const ${swrKeyFnName} = (${queryKeyProps}) => [\`${route}\`${
const swrMutationFetcherOptions =
!mutator && isRequestOptions ? 'options?: AxiosRequestConfig' : '';

const swrMutationFetcherArg = props.some(
(prop) => prop.type === GetterPropType.BODY,
)
? '{ arg }'
: '__';

const swrMutationFetcherFn = `
export const ${swrMutationFetcherName} = (${swrProps} ${swrMutationFetcherOptions}) => {
return (_: string, { arg }: { arg: Arguments }): ${swrMutationFetcherType} => {
return (_: string, ${swrMutationFetcherArg}: { arg: Arguments }): ${swrMutationFetcherType} => {
return ${operationName}(${httpFnProperties}${
swrMutationFetcherOptions.length ? ', options' : ''
});
Expand Down
21 changes: 21 additions & 0 deletions tests/specifications/petstore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
summary: Deletes a specific pet
operationId: deletePetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to delete
schema:
type: string
responses:
'204':
description: Expected response to a valid request
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/health:
get:
summary: health check
Expand Down