From 77d10b448c1a97729283219165283cb8023ac5d7 Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Sat, 16 Mar 2024 01:53:59 +0100 Subject: [PATCH] fix: name param __ in case of no body arg (#1263) Co-authored-by: Alfred Jonsson --- packages/swr/src/index.ts | 8 +++++++- tests/specifications/petstore.yaml | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index 462cfa7ca..e85b98178 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -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' : '' }); diff --git a/tests/specifications/petstore.yaml b/tests/specifications/petstore.yaml index ef67eae90..cde856ea4 100644 --- a/tests/specifications/petstore.yaml +++ b/tests/specifications/petstore.yaml @@ -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