Skip to content

covenix / Returns

Function: Returns()

Returns(status, schema?, options?): ClassDecorator & MethodDecorator

Defined in: src/decorators.ts:200

Declares a response for a status code. Stackable — apply once per status. The handler's return value is validated against the matching schema (a mismatch responds 500), and the schema is emitted in the generated OpenAPI document. Omit schema for a no-body response (e.g. @Returns(204)).

Usable on a method or on the controller class, where it declares a shared response merged into every route in the class (e.g. a common 401/422 error shape) — a route's own @Returns for the same status overrides the shared one.

Parameters

status

number

HTTP status code, e.g. 200.

schema?

ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

Zod schema for the response body; omit for no body.

options?

ReturnsOptions

Extra response metadata, e.g. headers or description.

Returns

ClassDecorator & MethodDecorator

Example

ts
@Route('users')
@Returns(401, ErrorSchema)   // shared by every route in the controller
@Returns(422, ErrorSchema)
class UsersController {
  @Get('{id}')
  @Returns(200, UserSchema)
  @Returns(404, NotFoundSchema) // route-specific, on top of the shared ones
  get() {}
}