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

[BUG] [typescript-angular] DELETE method - TS2554: Expected 1-2 arguments, but got 3 #10864

Open
constantant opened this issue Nov 16, 2021 · 27 comments

Comments

@constantant
Copy link

Description

It generates a wrong way to call the HttpClient.delete method

openapi-generator version
5.3.1-SNAPSHOT
OpenAPI declaration file content or url
"/v1/project/{projectId}": {
  "delete": {
    "tags": [
      "Project"
    ],
    "parameters": [
      {
        "name": "projectId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    ],
    "responses": {
      "200": {
        "description": "Success"
      }
    }
  }
}
Generation Details
return this.httpClient.delete<any>(`${this.configuration.basePath}/v1/project/${encodeURIComponent(String(projectId))}`,
    null, // <-- the issue
    {
        context: localVarHttpContext,
        responseType: <any>responseType_,
        withCredentials: this.configuration.withCredentials,
        headers: localVarHeaders,
        observe: observe,
        reportProgress: reportProgress
    }
);
Steps to reproduce

Generate from the DELETE method definition

Suggest a fix

In case of the DELETE method do not provide the body payload

@eiswind
Copy link

eiswind commented Dec 5, 2021

I see the same issue here with ng 13.0.1 and generator 5.3.1-SNAPSHOT

@PeterOeClausen
Copy link

I'm seeing the same issue with:

Angular CLI: 13.1.2
Node: 16.13.1
Package Manager: npm 8.3.0
OS: win32 x64

I ran:
npx @openapitools/openapi-generator-cli generate -i ./src/api/swagger.json -g typescript-angular -o ./src/api

Also seems like the methods like get, delete and so on of the httpClient of Angular 13.1.1 is only taking two arguments: The url and options:

https://github.com/angular/angular/blob/13.1.1/packages/common/http/src/client.ts#L941-L949

Once, it took a middle argument, body, but that's a long time ago. - Even at 5.0.x, it was only 2 arguments: https://github.com/angular/angular/blob/5.0.x/packages/common/http/src/client.ts

So it seems like a bug :)

@maxs-rose
Copy link

There is a PR for this here #10976

@coder925
Copy link

Suggest a fix
In case of the DELETE method do not provide the body payload

Isn't the fix simply to use the options.body property instead (as suggested in #11172 )?

I'm actually in need of a body for DELETE.

@amakhrov
Copy link
Contributor

Duplicate of #10975

@cghislai
Copy link
Contributor

cghislai commented Jan 27, 2022

@coder925 Unfortunately, the specification does not allow a body for delete methods. See https://swagger.io/specification/#operation-object mentionning The requestBody is only supported in HTTP methods where the HTTP 1.1 specification RFC7231 has explicitly defined semantics for request bodies. In other cases where the HTTP spec is vague, requestBody SHALL be ignored by consumers. and RFC7231 metionning A payload within a DELETE request message has no defined semantics;

When fixing this for angular13, i tried to update the test spec to include a delete body so that i could test the generated code, but i got errors due to the invalid spec. I think I edited a former spec I will give it another try

@EE1234EE
Copy link

Hey guys,

link to comment. I do not have a requestBody but still have the same issue.

@lfarci
Copy link

lfarci commented Jan 30, 2022

Same issue as @EE1234EE , I have a delete method without any request body and still get this issue.

Here is my specification:

delete:
      summary: Deletes a user by ID.
      operationId: 'deleteById'
      tags:
        - User
      parameters:
        - name: userId
          in: path
          required: true
          description: This is the user identifier.
          schema:
            type: integer
            format: int64
      responses:
        '204':
          description: The user has been successfuly deleted.
        '404':
          description: The user could not be deleted because it doesn't exist.
          content:
            application/json:
              schema:
                $ref: './resources/shared/ServiceError.yaml'

@maxs-rose
Copy link

The generator is attempting to add the request body whether it is in your specification or not that is why you are seeing the issues

@pwiesinger
Copy link

any updates regarding this issue?

@maxs-rose
Copy link

@pwiesinger a fix for this was merged in #10976 we are just waiting for a release that includes it

@Danielku15
Copy link
Contributor

There was a long ongoing discussion about delete bodies over here: OAI/OpenAPI-Specification#1801
The conclusion was: They should be supported and the 3.1 spec was updated accordingly.
OAI/OpenAPI-Specification#1937

Therefore I would vote to "revert the revert" and add proper support for bodies in delete methods. 😁

@cghislai
Copy link
Contributor

I am attempting to do so. What prompted the revert was that I couldn't produce a valid test spec with a delete body, but I hadn't noticed it was still using swagger v2.
Now I'm in the process of making sure the delete body is tested across all generators supporting v3, but pull requests are held in the queue waiting for review.
The fix itself was already committed in an abandoned pr here, it is quite comical the hurdle it causes with a fix somewhere in the history.
Anyway sorry for that it appeared to me the revert was the quickest way to fix the issue until proper testing was in place.

@matteobaldini-quix
Copy link

So just checking, a release with the proposed fixes isn't out yet? Right? If so how can we circumvent this issue while using ng13 and openapi generator?

@maxs-rose
Copy link

Using version 5.3.0 still seems to work with a13 for us at least

@chrisae
Copy link

chrisae commented Mar 18, 2022

With version 5.4.0 I'm also getting this error.

Using the decorators from @nestjs/swagger one of my delete functions looks like this:

@Delete(':id')
@ApiOkResponse({
  type: Boolean,
})
@ApiParam({ name: 'id' })
remove(@Param('id') id: string) {
  return this.projectsService.remove(id);
}

@Tasades
Copy link

Tasades commented Mar 21, 2022

We overided the api.service.mustache as quickfix that uses the options.body for deletes. Its a bit dirty but it works for us for now: api.service.mustache.zip

We use version 5.3.1
I hope it helps.

@yurakhomitsky
Copy link

5.3.0

where did you get this version? 2.4.26 is the latest

@mgol
Copy link

mgol commented Apr 15, 2022

5.3.0

where did you get this version? 2.4.26 is the latest

@yurakhomitsky You're talking about the version of @openapitools/openapi-generator-cli and the others about the version of the JAR that it uses. You can specify it in openapitools.json. See #10976 (comment) and my followup comment.

@yurakhomitsky
Copy link

5.3.0

where did you get this version? 2.4.26 is the latest

@yurakhomitsky You're talking about the version of @openapitools/openapi-generator-cli and the others about the version of the JAR that it uses. You can specify it in openapitools.json. See #10976 (comment) and my followup comment.

That's great but when this bug will be fixed and shipped via npm package?

@mgol
Copy link

mgol commented Apr 15, 2022

The bug is not in the npm package but in the external dependency it downloads. See the README:

The first time you run the command openapi-generator-cli the last stable version of OpenAPITools/openapi-generator is downloaded by default.

That version is saved in the file openapitools.json.

The fix is in 6.0.0-beta but even when they release it as stable it will not get autofixed for you because your openapitools.json file will contain a reference to an older version that you need to update by yourself. And you can already do that today byt pointing it to 6.0.0-beta. This version works for me without issues.

@yurakhomitsky
Copy link

yurakhomitsky commented Apr 15, 2022

The bug is not in the npm package but in the external dependency it downloads. See the README:

The first time you run the command openapi-generator-cli the last stable version of OpenAPITools/openapi-generator is downloaded by default.
That version is saved in the file openapitools.json.

The fix is in 6.0.0-beta but even when they release it as stable it will not get autofixed for you because your openapitools.json file will contain a reference to an older version that you need to update by yourself. And you can already do that today byt pointing it to 6.0.0-beta. This version works for me without issues.

Sounds like I will have to push the openapitools.json file to the git to keep the 6-beta version because we didn't keep it before the code was generated every time in the pipeline.

Also, the problem doesn't appear on this version of the package @openapitools/openapi-generator-cli": "^1.0.18-4.3.1"

I guess it generates the code of the Angular 11 version.

@paintcode
Copy link

Has this bug been resolved? I just upgraded from 5.4.0 (where I saw the bug) to 6.2.0, and so far it seems to be okay.

@amakhrov
Copy link
Contributor

@paintcode Yes it has been fixed.

This bug report effectively duplicates #10975 and as such should have been closed together with that one.
@wing328

@evanjmg
Copy link

evanjmg commented Oct 18, 2022

what version was this fixed in?

@amakhrov
Copy link
Contributor

Broken compilation was fixed in 6.0.0 (but still no body support in DELETE)
Full support for body in DELETE landed in 6.2.0

@sverbach-zuehlke
Copy link

Ran into the same issues. Out of the blue I couldn't generate code for DELETE endpoints anymore. Updating to the latest @openapitools/openapi-generator-cli also did not help.

Solved it by setting the 'ngVersion' additional-property to '12.0.0' (although the project is on v14) in the command:

openapi-generator-cli generate -i http://localhost:XXXX/.../swagger.json -g typescript-angular -o src/generated/api --additional-properties=withInterfaces=true --additional-properties=ngVersion=12.0.0

setting it to any major version above "12.0.0" will break the code generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests