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

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

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 20
  • Comments: 26 (6 by maintainers)

Most upvoted comments

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?

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.

There is a PR for this here #10976

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

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.

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

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

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.

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

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.