Skip to main content

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:

PropertyTypeDescription
kind'ArrayType'Always 'ArrayType'.
namestring | undefinedRegistry name. undefined for anonymous array types.
descriptionstring | undefinedHuman-readable description.
abstractboolean | undefinedWhether the type is abstract.
embeddedbooleantrue when the type has no name.
scopePattern(string | RegExp)[] | undefinedScopes this type is visible in.
examplesDataTypeExample[] | undefinedExample values for documentation.

Properties on ArrayType:

PropertyTypeDescription
typeComplexType | MixinType | MappedType | SimpleType | UnionType | EnumType | ArrayTypeThe element type. Every item in the array is validated against this type.
minOccursnumber | undefinedMinimum number of items.
maxOccursnumber | undefinedMaximum 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
}

ComplexType