covenix / BodyParam
Function: BodyParam()
BodyParam(
arg?):ParameterDecorator
Defined in: src/parameters.ts:96
Injects the request body. Three forms:
@BodyParam()— the whole body (the value parsed by@Bodywhen present, otherwise the rawreq.body).@BodyParam('field')— a single field of the parsed body.@BodyParam(schema)— the whole body, declaring its@Bodyschema inline. Sugar for a method-level@Body(schema)plus a name-less@BodyParam(), keeping the schema next to the parameter it feeds. Don't combine it with a separate@Bodyon the same handler (declaring the body twice throws).
Parameters
arg?
string | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
A field name (string), a @Body schema (ZodType), or omitted for the whole body.
Returns
ParameterDecorator
Example
ts
@Post()
@Returns(201, UserSchema)
create(@BodyParam(CreateUserSchema) user: z.infer<typeof CreateUserSchema>) {}