samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.84k stars 95 forks source link

Skip validation of content-type by TypedBody if body is empty #1094

Open kelchm opened 6 days ago

kelchm commented 6 days ago

Feature Request

In some cases I'd like to be able to make the body of a request optional. This seems to work as expected with @TypedBody, with the exception of it enforcing a check for a Content-Type of application/json:

https://github.com/samchon/nestia/blob/807474a7c7220922822e339f0c7d0dcd6d858491/packages/core/src/decorators/TypedBody.ts#L38-L41

I would argue that specifically in the case of a request with no body, there should be no expectation of a Content-Type header and therefore we should bypass this check. It would then be up to the validator to make a determination of whether this empty body is permissible.

samchon commented 3 days ago

You are meaning that when the request body parameter type is optional, right?