Skip to main content

API Reference

This page lists the first-version public API. The package may add APIs as samples and binding coverage grow, but this surface is the supported baseline.

Module

AsyncApiModule.forRoot(options?)

Registers global AsyncAPI configuration. Returns a global DynamicModule by default.

AsyncApiModule.forRoot({
defaultInfo: { title: 'Orders Service', version: '1.0.0' },
});
OptionPurpose
isGlobalDefaults to true; set false for module-scoped registration
defaultInfoDefault document info metadata as a string map

AsyncApiModule.forRootAsync(options)

Registers global configuration from a provider-backed factory.

AsyncApiModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
defaultInfo: { title: config.getOrThrow('SERVICE_NAME') },
}),
});
OptionPurpose
useFactoryFactory resolving the module options (sync or async)
injectProviders injected into the factory
importsModules imported for the factory's dependencies
extraProvidersAdditional providers registered alongside the options
isGlobalDefaults to true

AsyncApiModule.setup(path, app, document, options?)

Serves the viewer page plus the raw JSON and YAML on the application's HTTP server. Returns { uiUrl, jsonUrl, yamlUrl }. See Docs Route.

Decorators

See Decorators for full options.

DecoratorLevelPurpose
@AsyncApiChannel(id, options?)classDeclare the channel a handler operates on
@AsyncApiPub(options?)methodDeclare a send operation
@AsyncApiSub(options?)methodDeclare a receive operation
@AsyncApiMessage(payload, options?)methodDeclare the message payload
@AsyncApiHeaders(headers)methodDeclare the message headers
@AsyncApiServer(name, host, protocol, options?)classDeclare a broker (repeatable)
@AsyncApiChannelBindings(bindings)classAttach channel bindings
@AsyncApiOperationBindings(bindings)methodAttach operation bindings
@AsyncApiMessageBindings(bindings)methodAttach message bindings

Functions

getAsyncApiDocument(app, config?)

Walks the running application's NestJS metadata and returns a spec-compliant AsyncAPI 3.0 document. The AsyncAPI counterpart to SwaggerModule.createDocument. See Document Generation.

buildAsyncApiDocument(config, handlers)

Assembles a document from a config and a pre-scanned handler list. The lower-level building block getAsyncApiDocument calls after the metadata walk; useful for advanced custom discovery.

toJson(document) / toYaml(document)

Serialize a document to indented JSON or block-style YAML 1.2. Both are dependency-free.

escapeJsonPointerSegment(segment) / buildRef(base, ...segments)

RFC 6901 reference helpers used to build $ref strings whose segments may contain / or ~ (common with channel ids that mirror @EventPattern strings). Exported for advanced use.

Schema Sources

@AsyncApiMessage and @AsyncApiHeaders accept a SchemaSource:

  • A DTO class — resolved through the same @nestjs/swagger chain that documents HTTP bodies.
  • A JsonSchemaSource — a pre-computed { name, schema }, for example a Zod schema converted with z.toJSONSchema().

AsyncApiSchemaRegistry is the registry the generator uses to collect components.schemas and dedupe shared DTOs. See Validation.

Constants

  • ASYNC_API_VERSION — the emitted spec version (3.0.0).
  • AsyncApiAction — operation actions (Send, Receive).
  • AsyncApiProtocol — supported binding protocol keys (kafka, nats, mqtt, amqp).
  • DEFAULT_DOCUMENT_TITLE, DEFAULT_DOCUMENT_VERSION — config defaults.

Public API Tiers

Onboarding focuses on AsyncApiModule and the five decorators (@AsyncApiChannel, @AsyncApiPub / @AsyncApiSub, @AsyncApiMessage, @AsyncApiHeaders, @AsyncApiServer) plus getAsyncApiDocument and AsyncApiModule.setup.

Advanced features — binding decorators, buildAsyncApiDocument, AsyncApiSchemaRegistry, serializers, and reference helpers — stay in their own sections and are not needed for a first integration.