OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-fetch] PATCH requestBody overwrites DELETE requestBody

Open
#14,191 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
Description

When a PATCH and DELETE endpoint are registered under the same path, the requestBody from the PATCH endpoint is copied over to the requestBody from in the DELETE endpoint. While the DELETE endpoint has no requestBody defined at all.

openapi-generator version

docker openapitools/openapi-generator-cli:v6.2.0

OpenAPI declaration file content or url
/some/route/{id}:
    delete:
      tags:
        - Bookings
      parameters:
        - name: id
          in: path
          schema:
            type: string
          required: true
      responses:
        '200':
          description: Booking request successfully deleted

    patch:
      tags:
        - Bookings
      parameters:
        - name: id
          in: path
          schema:
            type: string
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                reason:
                  type: string
                  nullable: true
      responses:
        '200':
          description: Success
Generation Details

Typescript outputs:

export interface SomeRouteIdPatchRequest {
    id: string;
    SomeRouteIdDeleteRequest?: SomeRouteIdDeleteRequest;
}

export interface SomeRouteIdDeleteRequest {
    /**
     * @type {string}
     * @memberof SomeRouteIdDeleteRequest
     */
    reason?: string | null;
}

    async someRouteIdDelete(requestParameters: SomeRouteIdDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.someRouteIdDeleteRaw(requestParameters, initOverrides);
    }

As you can see, the reason field is suddenly a required field in the delete call, while it should only require the id parameter and no request body at all.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied OpenAPI declaration using openapitools/openapi-generator-cli:v6.2.0 and the typescript-fetch output. Inspect generation around SomeRouteIdPatchRequest and someRouteIdDelete; done means DELETE requires only id with no reason request body, while PATCH retains its own request body.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.