Skip to content

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 @Body when present, otherwise the raw req.body).
  • @BodyParam('field') — a single field of the parsed body.
  • @BodyParam(schema) — the whole body, declaring its @Body schema 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 @Body on 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>) {}