ArrayType
Package: @opra/common
ArrayType is the runtime class that represents a homogeneous array type in an OPRA document. It wraps a single element type and carries optional occurrence constraints. When you call the ArrayType(ElementType) factory function in your schema declarations, the result is a TypeScript class decorated with metadata — the actual ArrayType instance is created later, during document initialization.
The ArrayType(...) factory function is documented on the ArrayType page. This page covers the class instance you retrieve from a document.
Inheritance
DocumentElement
└── DataType
└── ArrayType
Properties
Properties inherited from DataType:
| Property | Type | Description |
|---|---|---|
kind | 'ArrayType' | Always 'ArrayType'. |
name | string | undefined | Registry name. undefined for anonymous array types. |
description | string | undefined | Human-readable description. |
abstract | boolean | undefined | Whether the type is abstract. |
embedded | boolean | true when the type has no name. |
scopePattern | (string | RegExp)[] | undefined | Scopes this type is visible in. |
examples | DataTypeExample[] | undefined | Example values for documentation. |
Properties on ArrayType:
| Property | Type | Description |
|---|---|---|
type | ComplexType | MixinType | MappedType | SimpleType | UnionType | EnumType | ArrayType | The element type. Every item in the array is validated against this type. |
minOccurs | number | undefined | Minimum number of items. |
maxOccurs | number | undefined | Maximum number of items. |
Methods
generateCodec(codec, options?)
Compiles a validation/transformation function that first validates each element against the element type's codec, then wraps the result in an array validator. minOccurs and maxOccurs constraints are applied after element validation.
const decoder = arrayType.generateCodec('decode', { scope: 'public' });
const encoded = arrayType.generateCodec('encode');
generateCodec(
codec: 'encode' | 'decode',
options?: DataType.GenerateCodecOptions
): Validator
extendsFrom()
Always returns false. ArrayType does not participate in inheritance chains.
extendsFrom(): boolean // always false
inScope(scope?)
Returns true if this type is visible in the given scope.
inScope(scope?: string | '*'): boolean
toJSON(options?)
Returns an OpraSchema.ArrayType plain object for schema export.
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.ArrayType
Obtaining an ArrayType instance
import { ArrayType } from '@opra/common';
const type = document.node.getDataType('Customer[]');
if (type instanceof ArrayType) {
console.log(type.kind); // 'ArrayType'
console.log(type.type.name); // 'Customer'
console.log(type.minOccurs); // number | undefined
}