MQHeader
Package: @opra/common
MQHeader is the runtime class that represents a message header declared on an MQController or MQOperation. Headers carry metadata alongside a message — correlation IDs, routing keys, content-type hints, and similar transport-level values.
Inheritance
DocumentElement
└── Value
└── MQHeader
Value contributes the core name/type pair. MQHeader adds lifecycle and validation metadata.
Properties
Properties inherited from Value:
| Property | Type | Description |
|---|---|---|
name | string | RegExp | Header name. May be a RegExp to match multiple headers with a single declaration. |
type | DataType | undefined | The data type used for encoding and decoding the header value. |
description | string | undefined | Human-readable description. |
isArray | boolean | undefined | Whether the header holds an array of values. |
examples | any[] | undefined | Example values for documentation. |
Properties on MQHeader:
| Property | Type | Description |
|---|---|---|
required | boolean | undefined | Header must be present in the message. |
deprecated | boolean | string | undefined | Marks the header as deprecated. Pass a string for a deprecation message. |
designType | Type | undefined | TypeScript constructor type from design:type metadata. |
Methods
generateCodec(codec, options?)
Compiles a validation/transformation function for encoding (output) or decoding (input) the header value according to its declared type.
const decoder = header.generateCodec('decode');
const encoder = header.generateCodec('encode');
generateCodec(
codec: 'encode' | 'decode',
options?: DataType.GenerateCodecOptions,
): Validator
toJSON(options?)
Returns a plain OpraSchema.MQHeader object for schema export.
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.MQHeader
Obtaining an MQHeader instance
Headers are retrieved via MQController.findHeader() or MQOperation.findHeader().
const ctrl = document.api.findController('CustomerQueue');
const header = ctrl?.findHeader('x-correlation-id');
if (header) {
console.log(header.name); // 'x-correlation-id'
console.log(header.required); // true | false | undefined
const decoder = header.generateCodec('decode');
}