lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.56k stars 503 forks source link

API hangs when sending an empty object #1325

Open Muratcol opened 2 years ago

Muratcol commented 2 years ago

In POST requests, when an empty JSON object is sent, the API hangs and the request cannot access the controller function at all.

Sorting

Expected Behavior

If there is no mandatory parameter in the sent request, the validation errors should be returned.

Current Behavior

Screenshot_20221018_105043

Steps to Reproduce

  1. Having a controller f.e
    @Post("htmltoimage")
    @Security("jwt", [Rights.MICROSERVICES_MEDIA_SERVICES])
    async postStart(
        @Body() requestBody: HTMLToImage.RequestBody,
        @Request() req: Express.Request
    ): Promise<HTMLToImage.Response> {
        this.setStatus(200);
        return  await new HTMLToImageService().start(req);
    }
  2. Sending an empty JSON Object { } to the that endpoint

Context (Environment)

Version of the library: 4.1.3 Version of NodeJS: v16.13.1

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

jackey8616 commented 1 year ago

@Muratcol Can you provide more codes? I can't reproduce with test cases in tsoa:

// tests/integration/...
    it('should invalid empty request body', () => {
      return verifyPostRequest(
        `${basePath}/Validate/body`,
        {},
        (_err, res) => {
          console.log(res);
        },
      );
    });
midoelhawy commented 5 months ago

Hi @Muratcol,

Can you provide more code for the HTMLToImageService class? I think the problem is in your approach because I can't reproduce the issue.