An Open Type Contract (OTC) defines a kind of value that systems can refer to by name. Its fields describe what the value contains, what those parts mean in the domain, and which constraints they must satisfy. A producer and a consumer can refer to the same type when they exchange data, even when they represent that data differently in their own code.
Scope and validation
A type author can build on an existing definition through inheritance or mixins, or give a field another named type. These relationships let a catalogue describe a domain using connected definitions. The contract can also carry guidance for presenting or handling a value, including labels, accessibility information and privacy hints.
Two different documents may need checking. The OTC schema checks that the type definition is well formed. To check a value supplied by an application, a consumer resolves the referenced types and applies the constraints for instances. Clients also implement any presentation or handling hints they support. An operation can declare one of these types as its input or output. See the function registry.
Field reference
Read each table within its named object. A required field must be present whenever that object is supplied. Brackets ([]) denote one array entry. Each object in the tables accepts only its listed fields.
Document
Field
JSON type
Required
Meaning and constraints
otc
string
Yes
OTC specification version. Use three dot-separated numbers.
id
string
Yes
Unique namespaced type identifier. Use at least four dot-separated segments. Each starts with a lowercase letter and continues with lowercase letters or digits.
name
string
Yes
Human-readable type name. Length: 1–100 characters.
description
string
Yes
Purpose description of the type. Must be nonempty.
fields
array of objects
Yes
Field definitions. At least one entry is required.
abstract
boolean
No
If true, type cannot be instantiated directly. Schema default: false.
deprecated
boolean
No
If true, type is deprecated. Schema default: false.
deprecatedReason
string
No
Reason for deprecation.
examples
array of values
No
Example values.
extends
string
No
Parent type ID to inherit from. Use at least four dot-separated segments. Each starts with a lowercase letter and continues with lowercase letters or digits.
implementations
array of objects
No
Language-specific bindings.
metadata
object
No
Additional metadata.
mixins
array of strings
No
Mixin type IDs for composition. Each entry is a qualified catalogue identifier of at least four segments.
schema
object
No
JSON Schema representation.
status
string
No
Stability status. Allowed values are draft, stable, deprecated.
tags
array of strings
No
Classification tags.
version
string
No
Type version (semver). Use three dot-separated numbers.
fields[]
Field
JSON type
Required
Meaning and constraints
name
string
Yes
Field name in camelCase. Start with a lowercase letter, followed by letters or digits.
type
string
Yes
Primitive name (string, integer, number, boolean, array, object, null) or $ref: followed by a qualified type identifier, such as $ref:example.orders.type.customer.
constraints
object
No
Limits a value of this field must satisfy.
default
any JSON value
No
Default value for the field.
description
string
No
Field description.
examples
array of values
No
Example values.
hints
object
No
Guidance for clients displaying or handling this field.
meaning
string
No
Semantic meaning tag. Use two dot-separated names, as in order.deliveryDate. The first starts with a lowercase letter and continues with lowercase letters or digits. The second starts with a letter and continues with letters or digits.
required
boolean
No
Whether field is required.
fields[].constraints
Field
JSON type
Required
Meaning and constraints
const
any JSON value
No
Exact required value.
enum
array of values
No
Allowed values. At least one entry is required.
exclusiveMaximum
number
No
Exclusive maximum value.
exclusiveMinimum
number
No
Exclusive minimum value.
format
string
No
Format identifier. Allowed values are email, uri, url, uuid, date, time, date-time, duration, ipv4, ipv6, hostname, phone, credit-card, iban, bic.
maxItems
integer
No
Maximum array length. Minimum: 0.
maxLength
integer
No
Maximum string length. Minimum: 0.
maximum
number
No
Maximum numeric value.
minItems
integer
No
Minimum array length. Minimum: 0.
minLength
integer
No
Minimum string length. Minimum: 0.
minimum
number
No
Minimum numeric value.
multipleOf
number
No
Value must be multiple of this. Must be greater than 0.
nullable
boolean
No
Field may be null.
pattern
string
No
Regex pattern for validation.
required
boolean
No
Field must be present.
uniqueItems
boolean
No
Array items must be unique.
fields[].hints
Field
JSON type
Required
Meaning and constraints
a11y
object
No
Accessibility information for assistive technology.
i18n
object
No
Translation keys for text associated with the field.
privacy
object
No
Guidance for handling and storing the value.
ui
object
No
Guidance for presenting the field in a user interface.
fields[].hints.a11y
Field
JSON type
Required
Meaning and constraints
description
string
No
Screen reader description i18n key.
invalid
boolean
No
Announce as invalid.
live
string
No
ARIA live region type. Allowed values are off, polite, assertive.
required
boolean
No
Announce as required.
role
string
No
ARIA role.
fields[].hints.i18n
Field
JSON type
Required
Meaning and constraints
error
string
No
Error message i18n key.
help
string
No
Help text i18n key.
label
string
No
Label i18n key.
placeholder
string
No
Placeholder i18n key.
unit
string
No
Unit label i18n key.
fields[].hints.privacy
Field
JSON type
Required
Meaning and constraints
audit
boolean
No
Include in audit logs.
mask
boolean
No
Mask in logs and displays.
retention
string
No
Data retention policy. Allowed values are none, session, persistent.
sensitivity
string
No
Data sensitivity level. Allowed values are public, internal, pii, secret.
fields[].hints.ui
Field
JSON type
Required
Meaning and constraints
autocomplete
string
No
HTML autocomplete attribute.
group
string
No
Field grouping identifier.
hidden
boolean
No
Hide from UI.
inputType
string
No
HTML input type. Allowed values are text, email, password, number, tel, url, date, time, datetime-local, color, file, checkbox, radio, range, hidden, search.
The type okham.memory.type.save.request describes the value that Memory passes to its classification operation. A field can carry a description, a semantic tag in meaning, a default or examples. Its boolean required describes whether a value of this type must include the field. In the example, fields declares a required object named payload. A save request supplies a value for payload. The type definition itself describes that value.
Constraints, relations and reuse
Put limits on a field in constraints. For example, enum enumerates allowed values, minLength bounds a string, and minimum bounds a number. The schema also defines limits for arrays, patterns, formats and nullability.
Use extends for one parent type and mixins for a list of type references to compose. A field can refer to another type, for example $ref:example.orders.type.customer. Resolving these references requires the referenced definitions.
Use hints.ui, hints.i18n, hints.a11y or hints.privacy on a field to guide presentation and handling. A consumer implements the indicated behaviour.
At type level, schema can carry JSON Schema for validating instances. examples supplies example values and implementations can describe language-specific bindings. version, status, abstract, deprecated, deprecatedReason, tags and metadata describe the type's lifecycle and catalogue entry.
Validate the definition against the OTC schema. To check a particular save request, resolve its type and validate the request against the rules for instances of that type.