Skip to content

Commit

Permalink
fix: name param __ in case of no body arg (#1263)
Browse files Browse the repository at this point in the history
Co-authored-by: Alfred Jonsson <alfred.jonsson@decerno.se>
  • Loading branch information
AffeJonsson and Alfred Jonsson committed Mar 16, 2024
1 parent 9c13f1f commit 77d10b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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

0 comments on commit 77d10b4

Please sign in to comment.