@amqp-contract/asyncapi
@amqp-contract/asyncapi
Classes
AsyncAPIGenerator
Defined in: index.ts:149
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 { 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'
})
}
});
// Zod 4 converts itself (Standard JSON Schema): no schemaConverters needed.
const generator = new AsyncAPIGenerator();
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:160
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:195
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:100
Options for generating an AsyncAPI document. These correspond to the top-level AsyncAPI document fields.
AsyncAPIGeneratorOptions
type AsyncAPIGeneratorOptions = object;Defined in: index.ts:61
Options for configuring the AsyncAPI generator.
Example
import { AsyncAPIGenerator } from '@amqp-contract/asyncapi';
import { experimental_ValibotToJsonSchemaConverter } from '@orpc/valibot';
// Zod 4 and ArkType schemas convert natively; Valibot needs a converter.
const generator = new AsyncAPIGenerator({
schemaConverters: [new experimental_ValibotToJsonSchemaConverter()]
});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:93 |
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:83 |
logger.warn | (message) => void | - | index.ts:83 |
schemaConverters? | SchemaConverter[] | Schema converters for schemas that do not convert themselves. A schema implementing Standard JSON Schema (~standard.jsonSchema, e.g. Zod 4 and ArkType) is converted natively and needs none. The converters are the fallback for the rest (e.g. Valibot via @orpc/valibot), tried in order until one's condition matches. | index.ts:70 |
vhost? | string | The RabbitMQ virtual host written into every channel's AMQP binding (bindings.amqp.queue.vhost / bindings.amqp.exchange.vhost). Default "/" | index.ts:77 |
SchemaConverter
type SchemaConverter = object;Defined in: index.ts:32
Converts a Standard Schema to JSON Schema for libraries that do not expose ~standard.jsonSchema themselves (e.g. Valibot).
Structurally the oRPC ConditionalSchemaConverter, so the @orpc/zod, @orpc/valibot and @orpc/arktype converters plug in directly — without this package depending on @orpc/openapi.
Methods
condition()
condition(schema, options): boolean | Promise<boolean>;Defined in: index.ts:34
Whether this converter handles schema.
Parameters
| Parameter | Type |
|---|---|
schema | StandardSchemaV1<unknown, unknown> | undefined |
options | { strategy: "input"; } |
options.strategy | "input" |
Returns
boolean | Promise<boolean>
convert()
convert(schema, options):
| [required: boolean, jsonSchema: JSONSchema]
| Promise<[required: boolean, jsonSchema: JSONSchema]>;Defined in: index.ts:39
Convert schema; the second tuple element is the JSON Schema.
Parameters
| Parameter | Type |
|---|---|
schema | StandardSchemaV1<unknown, unknown> | undefined |
options | { strategy: "input"; } |
options.strategy | "input" |
Returns
| [required: boolean, jsonSchema: JSONSchema] | Promise<[required: boolean, jsonSchema: JSONSchema]>