@amqp-contract/asyncapi
@amqp-contract/asyncapi
Classes
AsyncAPIGenerator
Defined in: index.ts:93
Generator for creating AsyncAPI 3.0 documentation from AMQP contracts.
This class converts contract definitions into AsyncAPI 3.0 specification documents, which can be used for API documentation, code generation, and tooling integration.
Example
import { AsyncAPIGenerator } from '@amqp-contract/asyncapi';
import { zodToJsonSchema } from '@orpc/zod';
import { z } from 'zod';
const contract = defineContract({
exchanges: {
orders: defineExchange('orders', 'topic', { durable: true })
},
publishers: {
orderCreated: definePublisher('orders', z.object({
orderId: z.string(),
amount: z.number()
}), {
routingKey: 'order.created'
})
}
});
const generator = new AsyncAPIGenerator({
schemaConverters: [zodToJsonSchema]
});
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:101
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:133
Generate an AsyncAPI 3.0 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.0 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, "id" | "info" | "servers">;Defined in: index.ts:44
Options for generating an AsyncAPI document. These correspond to the top-level AsyncAPI document fields.
AsyncAPIGeneratorOptions
type AsyncAPIGeneratorOptions = object;Defined in: index.ts:32
Options for configuring the AsyncAPI generator.
Example
import { AsyncAPIGenerator } from '@amqp-contract/asyncapi';
import { zodToJsonSchema } from '@orpc/zod';
const generator = new AsyncAPIGenerator({
schemaConverters: [zodToJsonSchema]
});Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
schemaConverters? | ConditionalSchemaConverter[] | Schema converters for transforming validation schemas to JSON Schema. Supports Zod, Valibot, ArkType, and other Standard Schema v1 compatible libraries. | index.ts:37 |