@amqp-contract/asyncapi
@amqp-contract/asyncapi
Classes
AsyncAPIGenerator
Defined in: index.ts:114
Generator for creating AsyncAPI 3.1 documentation from AMQP contracts.
This class converts contract definitions into AsyncAPI 3.1 specification documents, which can be used for API documentation, code generation, and tooling integration.
Example
import { AsyncAPIGenerator } from '@amqp-contract/asyncapi';
import { defineExchange, defineMessage, defineContract, definePublisher } from '@amqp-contract/contract';
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4';
import { z } from 'zod';
const ordersExchange = defineExchange('orders');
const orderMessage = defineMessage(z.object({
orderId: z.string(),
amount: z.number()
}));
const contract = defineContract({
publishers: {
orderCreated: definePublisher(ordersExchange, orderMessage, {
routingKey: 'order.created'
})
}
});
const generator = new AsyncAPIGenerator({
schemaConverters: [new ZodToJsonSchemaConverter()]
});
const asyncapi = await generator.generate(contract, {
id: 'urn:com:example:order-service',
info: {
title: 'Order Service API',
version: '1.0.0',
description: 'Async API for order processing'
},
servers: {
production: {
host: 'rabbitmq.example.com',
protocol: 'amqp',
protocolVersion: '0.9.1'
}
}
});Constructors
Constructor
new AsyncAPIGenerator(options?): AsyncAPIGenerator;Defined in: index.ts:124
Create a new AsyncAPI generator instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | AsyncAPIGeneratorOptions | Configuration options including schema converters |
Returns
Methods
generate()
generate(contract, options): Promise<AsyncAPIObject>;Defined in: index.ts:158
Generate an AsyncAPI 3.1 document from a contract definition.
Converts AMQP exchanges, queues, publishers, and consumers into AsyncAPI channels, operations, and messages with proper JSON Schema validation definitions.
Parameters
| Parameter | Type | Description |
|---|---|---|
contract | ContractDefinition | The AMQP contract definition to convert |
options | AsyncAPIGeneratorGenerateOptions | AsyncAPI document metadata (id, info, servers) |
Returns
Promise<AsyncAPIObject>
Promise resolving to a complete AsyncAPI 3.1 document
Example
const asyncapi = await generator.generate(contract, {
id: 'urn:com:example:api',
info: {
title: 'My API',
version: '1.0.0'
},
servers: {
dev: {
host: 'localhost:5672',
protocol: 'amqp'
}
}
});Type Aliases
AsyncAPIGeneratorGenerateOptions
type AsyncAPIGeneratorGenerateOptions = Pick<AsyncAPIObject, "info"> & Partial<Pick<AsyncAPIObject, "id" | "servers">>;Defined in: index.ts:63
Options for generating an AsyncAPI document. These correspond to the top-level AsyncAPI document fields.
AsyncAPIGeneratorOptions
type AsyncAPIGeneratorOptions = object;Defined in: index.ts:35
Options for configuring the AsyncAPI generator.
Example
import { AsyncAPIGenerator } from '@amqp-contract/asyncapi';
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4';
const generator = new AsyncAPIGenerator({
schemaConverters: [new ZodToJsonSchemaConverter()]
});Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
failOnMissingConverter? | boolean | If true (the default), the generator throws when a payload schema cannot be converted by any of the configured schemaConverters — a spec that silently degrades schemas to { type: "object" } placeholders lies to every consumer of the document (docs, codegen, tooling). Set to false to fall back to the generic placeholder with a warning instead. | index.ts:56 |
logger? | object | Optional logger for warnings during generation (e.g. unmatched schema converters). Structurally compatible with @amqp-contract/core's Logger — pass the same instance you hand to the client/worker. | index.ts:46 |
logger.warn | (message) => void | - | index.ts:46 |
schemaConverters? | ConditionalSchemaConverter[] | Schema converters for transforming validation schemas to JSON Schema. Supports Zod, Valibot, ArkType, and other Standard Schema v1 compatible libraries. | index.ts:40 |