Skip to content

@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

typescript
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
ts
new AsyncAPIGenerator(options): AsyncAPIGenerator;

Defined in: index.ts:101

Create a new AsyncAPI generator instance.

Parameters
ParameterTypeDescription
optionsAsyncAPIGeneratorOptionsConfiguration options including schema converters
Returns

AsyncAPIGenerator

Methods

generate()
ts
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
ParameterTypeDescription
contractContractDefinitionThe AMQP contract definition to convert
optionsAsyncAPIGeneratorGenerateOptionsAsyncAPI document metadata (id, info, servers)
Returns

Promise<AsyncAPIObject>

Promise resolving to a complete AsyncAPI 3.0 document

Example
typescript
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

ts
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

ts
type AsyncAPIGeneratorOptions = object;

Defined in: index.ts:32

Options for configuring the AsyncAPI generator.

Example

typescript
import { AsyncAPIGenerator } from '@amqp-contract/asyncapi';
import { zodToJsonSchema } from '@orpc/zod';

const generator = new AsyncAPIGenerator({
  schemaConverters: [zodToJsonSchema]
});

Properties

PropertyTypeDescriptionDefined 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

Released under the MIT License.