Skip to main content

Decorators

The package mirrors @nestjs/swagger naming. Five decorators describe the AsyncAPI 3.0 model, and three optional decorators attach protocol bindings (see Bindings).

@AsyncApiChannel(id, options?)

Class-level. Declares the AsyncAPI 3.0 channel a handler class operates on, mirroring how @Controller('path') declares an HTTP base route. The channel id is explicit by design — the generator never derives it from the class name.

@AsyncApiChannel('orders', {
address: 'orders.v1',
title: 'Orders',
description: 'Lifecycle events for customer orders.',
})
export class OrdersHandler {}
OptionPurpose
addressChannel address (topic, queue, routing key). Defaults to the id; pass null to mark an address unknown at design time
titleHuman-friendly channel title
summaryShort channel summary
descriptionVerbose channel description

@AsyncApiPub(options?) / @AsyncApiSub(options?)

Method-level. Declare an AsyncAPI 3.0 operation on a channel handler method. @AsyncApiPub produces a send operation; @AsyncApiSub produces a receive operation. The action is fixed by the decorator and is not configurable.

@AsyncApiPub({ operationId: 'orderPlaced', summary: 'A customer placed an order.' })
publishOrderPlaced(): void {}

@AsyncApiSub({ operationId: 'onOrderPlaced' })
handleOrderPlaced(): void {}
OptionPurpose
operationIdKey in the generated operations map. Defaults to the method name
titleHuman-friendly operation title
summaryShort operation summary
descriptionVerbose operation description

The 3.0 naming flips relative to 2.x: a send operation is @AsyncApiPub, and a receive operation is @AsyncApiSub. See Migration.

@AsyncApiMessage(payload, options?)

Method-level. Declares the payload of the message an operation sends or receives. The payload is either a DTO class — turned into JSON Schema through the same @nestjs/swagger chain that documents HTTP bodies — or a pre-computed { name, schema } source (for example a Zod schema converted with z.toJSONSchema()). The message is registered once in components.messages and referenced from the channel and operation.

@AsyncApiMessage(OrderPlacedDto, {
name: 'OrderPlaced',
summary: 'A customer placed an order.',
})
publishOrderPlaced(): void {}
OptionPurpose
namecomponents.messages key and message name. Defaults to the DTO class name or the schema source name
titleHuman-friendly message title
summaryShort message summary
descriptionVerbose message description
contentTypePayload content type. Defaults to application/json

@AsyncApiHeaders(headers)

Method-level. Declares the headers of the message an operation sends or receives, resolved exactly as the payload is — a DTO class through the @nestjs/swagger chain, or a pre-computed { name, schema }.

@AsyncApiMessage(OrderPlacedDto)
@AsyncApiHeaders(OrderHeadersDto)
publishOrderPlaced(): void {}

@AsyncApiServer(name, host, protocol, options?)

Class-level and repeatable. Declares a broker the application connects to. Stacking it declares several brokers, and every declaration across the application is merged into the document's servers map. The protocol and the optional protocol bindings carry the transport identity and connection metadata.

@AsyncApiServer('kafka', 'kafka.example.com:9092', 'kafka', {
title: 'Kafka cluster',
bindings: { kafka: { bindingVersion: '0.5.0' } },
})
@AsyncApiServer('nats', 'nats.example.com:4222', 'nats')
export class OrdersHandler {}
Argument / optionPurpose
nameKey in the generated servers map
hostServer host (may include the port)
protocolConnection protocol (kafka, nats, mqtt, amqp, …)
protocolVersionProtocol version used for connection
pathnamePath to a resource in the host
title / summary / descriptionServer metadata
bindingsProtocol-specific connection bindings, keyed by protocol

Binding Decorators

Three optional decorators attach protocol-specific bindings:

  • @AsyncApiChannelBindings(bindings) — class-level, alongside @AsyncApiChannel.
  • @AsyncApiOperationBindings(bindings) — method-level, alongside the operation.
  • @AsyncApiMessageBindings(bindings) — method-level, alongside the message.

See Bindings for the full Kafka, NATS, MQTT, and AMQP binding shapes.