Schema
Overview
An OPRA document is a JSON/YAML object that describes a complete API — its metadata, shared data types, linked documents, and API transport definitions.
- TypeScript
- JSON
- YAML
interface ApiDocument {
// OPRA specification version. Always "1.0".
spec: '1.0';
// Optional URL where this document can be fetched.
// Example: 'https://api.example.com/opra.json'
url?: string;
// Human-readable metadata about the document. → See: Document Info
// Example: { title: 'Customer API', version: '1.0', description: 'Manages customer records.' }
info?: DocumentInfo;
// Named data types shared across the document. → See: Type Definitions
// Example: { Customer: { kind: 'ComplexType', fields: { ... } } }
types?: Record<string, DataType>;
// Linked documents keyed by namespace alias. → See: References
// Example: { cm: { url: 'https://api.example.com/customer-models/opra.json', info: { ... } } }
references?: Record<string, DocumentReference>;
// API transport definition. → See: HTTP API Schema / MQ API Schema / WebSocket API Schema
// Example: { transport: 'http', name: 'CustomerApi', url: '/api', controllers: { ... } }
api?: HttpApi | MQApi | WSApi;
}
{
"spec": "1.0",
"url": "https://api.example.com/opra.json",
"info": { },
"types": { },
"references": { },
"api": { }
}
# OPRA specification version. Always "1.0".
spec: "1.0"
# Optional URL where this document can be fetched.
# Example: https://api.example.com/opra.json
url: https://api.example.com/opra.json
# Human-readable metadata about the document. → See: Document Info
info:
# Named data types shared across the document. → See: Type Definitions
types:
# Linked documents keyed by namespace alias. → See: References
references:
# API transport definition. → See: HTTP API Schema / MQ API Schema / WebSocket API Schema
api:
| Field | Type | Description |
|---|---|---|
spec | string | OPRA specification version. Always "1.0". |
url | string | Optional URL where this document can be fetched. |
info | DocumentInfo | Human-readable metadata (title, version, contact…). |
types | Record<string, DataType> | Named data types shared across the document. |
references | Record<string, DocumentReference> | Linked documents, keyed by namespace. |
api | HttpApi | MQApi | WSApi | API transport definition. |
Document Info
The info object carries human-readable metadata about the document.
- TypeScript
- JSON
- YAML
interface DocumentInfo {
// Display name of the API.
// Example: 'Customer API'
title?: string;
// API version string.
// Example: '1.0'
version?: string;
// Long-form description of the API.
// Example: 'Manages customer records and orders.'
description?: string;
// URL to the terms of service page.
// Example: 'https://example.com/terms'
termsOfService?: string;
// List of contact persons. → See: ContactPerson
// Example: [{ name: 'API Support', email: 'api@example.com', url: 'https://example.com/support' }]
contact?: ContactPerson[];
// License information. → See: LicenseInfo
// Example: { name: 'MIT', url: 'https://opensource.org/licenses/MIT' }
license?: LicenseInfo;
}
interface ContactPerson {
// Full name of the contact person.
name?: string;
// Contact email address.
email?: string;
// Contact URL.
url?: string;
}
interface LicenseInfo {
// License identifier. Required.
// Example: 'MIT'
name: string;
// URL to the full license text.
// Example: 'https://opensource.org/licenses/MIT'
url?: string;
// Inline license text (alternative to url).
content?: string;
}
{
"info": {
"title": "Customer API",
"version": "1.0",
"description": "Manages customer records and orders.",
"termsOfService": "https://example.com/terms",
"contact": [
{
"name": "API Support",
"email": "api@example.com",
"url": "https://example.com/support"
}
],
"license": {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
}
}
}
info:
# Display name of the API.
title: Customer API
# API version string.
version: "1.0"
# Long-form description of the API.
description: Manages customer records and orders.
# URL to the terms of service page.
termsOfService: https://example.com/terms
# List of contact persons.
contact:
- # Full name of the contact person.
name: API Support
# Contact email address.
email: api@example.com
# Contact URL.
url: https://example.com/support
# License information. name is required.
license:
name: MIT
url: https://opensource.org/licenses/MIT
| Field | Type | Description |
|---|---|---|
title | string | Display name of the API. |
version | string | API version string. |
description | string | Long-form description. |
termsOfService | string | URL to terms of service. |
contact | ContactPerson[] | List of contact persons. |
license | LicenseInfo | License name and URL. |
ContactPerson
| Field | Type | Description |
|---|---|---|
name | string | Contact person's name. |
email | string | Contact email address. |
url | string | Contact URL. |
LicenseInfo
| Field | Type | Description |
|---|---|---|
name | string | License name (e.g. "MIT"). Required. |
url | string | URL to the license text. |
content | string | Inline license text. |
Type Definitions
The types field is a record of named data types. Each entry is keyed by the type name and has a kind field that identifies its category.
- TypeScript
- JSON
- YAML
// All type definitions share these common fields.
interface DataTypeBase {
// Type category. Required.
kind: 'SimpleType' | 'EnumType' | 'ComplexType' | 'ArrayType'
| 'MappedType' | 'MixinType' | 'UnionType';
// Human-readable description of the type.
// Example: 'A postal address with city and country.'
description?: string;
// When true, this type cannot be used directly in fields — only extended.
abstract?: boolean;
// Example values shown in schema documentation. → See: DataTypeExample
// Example: [{ value: 'john@example.com', description: 'Standard email' }]
examples?: DataTypeExample[];
}
interface DataTypeExample {
// The example value.
value?: any;
// Optional label for this example.
description?: string;
}
{
"types": {
"Address": { "kind": "ComplexType" },
"Gender": { "kind": "EnumType" },
"Tags": { "kind": "ArrayType" }
}
}
types:
# Structured object type. → See: ComplexType
Address:
kind: ComplexType
# Closed set of allowed values. → See: EnumType
Gender:
kind: EnumType
# Typed array wrapper. → See: ArrayType
Tags:
kind: ArrayType
All type definitions share these common fields:
| Field | Type | Description |
|---|---|---|
kind | string | Type category. One of SimpleType, EnumType, ComplexType, ArrayType, MappedType, MixinType, UnionType. Required. |
description | string | Human-readable description. |
abstract | boolean | Cannot be used directly in fields — only extended. |
examples | DataTypeExample[] | Example values for documentation. |
DataTypeExample
| Field | Type | Description |
|---|---|---|
value | any | The example value. |
description | string | Optional label for this example. |
SimpleType
Represents a scalar value. Built on a named base type with optional attribute constraints.
- TypeScript
- JSON
- YAML
interface SimpleType extends DataTypeBase {
kind: 'SimpleType';
// Name of the parent SimpleType to extend.
// Built-in bases: 'string' | 'number' | 'integer' | 'boolean' | 'date' | 'uuid' | 'email' | …
// → See: Simple Types > Built-in Simple Types
base?: string;
// Attribute values that constrain validation at encode/decode time.
// → See: Simple Types > Type Attributes
// Example: { minLength: 3, maxLength: 64, pattern: '^[a-z0-9-]+$' }
properties?: Record<string, any>;
// Maps the OPRA type name to language-specific type names.
// Example: { js: 'string', json: 'string' }
nameMappings?: Record<string, string>;
}
{
"kind": "SimpleType",
"base": "string",
"description": "URL-friendly slug",
"properties": {
"minLength": 3,
"maxLength": 64,
"pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
}
}
kind: SimpleType
# Name of the parent SimpleType to extend.
# Built-in options: string, number, integer, boolean, date, uuid, email … → See: Simple Types
base: string
# Human-readable description of the type.
description: URL-friendly slug
# Attribute values that constrain validation. → See: Simple Types > Type Attributes
properties:
# Minimum character count.
minLength: 3
# Maximum character count.
maxLength: 64
# Regex the value must match.
pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$"
| Field | Type | Description |
|---|---|---|
base | string | Name of the parent SimpleType (e.g. "string", "number"). |
properties | Record<string, any> | Attribute values that constrain validation. |
nameMappings | Record<string, string> | Maps the OPRA type name to language-specific names (e.g. { "js": "string" }). |
EnumType
A closed set of allowed values.
- TypeScript
- JSON
- YAML
interface EnumType extends DataTypeBase {
kind: 'EnumType';
// Name of a parent EnumType whose values are inherited.
// → See: Enum Types > Inheritance
base?: string;
// Map of accepted wire values to their metadata.
// Keys are the values validated at runtime (e.g. 'M', not 'MALE').
// → See: Enum Types > Encode / Decode Behaviour
// Example: { M: { alias: 'MALE', description: 'Male' }, F: { alias: 'FEMALE', description: 'Female' } }
attributes: Record<string, EnumValueInfo>;
}
interface EnumValueInfo {
// Human-readable key (e.g. the enum key 'MALE' for wire value 'M').
// Not accepted as a wire value at runtime.
alias?: string;
// Description of this value.
description?: string;
}
{
"kind": "EnumType",
"description": "The gender of a person",
"attributes": {
"M": { "alias": "MALE", "description": "Male" },
"F": { "alias": "FEMALE", "description": "Female" },
"O": { "alias": "OTHER", "description": "Other" },
"U": { "alias": "UNKNOWN", "description": "Unknown" }
}
}
kind: EnumType
# Human-readable description of the type.
description: The gender of a person
# Map of accepted wire values to their metadata.
# Keys are the runtime-validated wire values (e.g. 'M'), not the human-readable keys.
# → See: Enum Types > Encode / Decode Behaviour
attributes:
M:
# Human-readable key. Not accepted as a wire value at runtime.
alias: MALE
description: Male
F:
alias: FEMALE
description: Female
O:
alias: OTHER
description: Other
U:
alias: UNKNOWN
description: Unknown
Extending another EnumType with base:
- TypeScript
- JSON
- YAML
// Extends the 'Gender' type, inheriting its values (M, F),
// and adds two more (O, U). → See: Enum Types > Inheritance
const AdministrativeGender: EnumType = {
kind: 'EnumType',
base: 'Gender',
description: 'Extended gender classification for administrative use',
attributes: {
O: { alias: 'OTHER', description: 'Other / non-binary' },
U: { alias: 'UNKNOWN', description: 'Not specified' },
},
};
{
"kind": "EnumType",
"base": "Gender",
"description": "Extended gender classification",
"attributes": {
"O": { "alias": "OTHER", "description": "Other / non-binary" },
"U": { "alias": "UNKNOWN", "description": "Not specified" }
}
}
kind: EnumType
# Name of the parent EnumType to extend. All base values are inherited.
# → See: Enum Types > Inheritance
base: Gender
# Human-readable description of the type.
description: Extended gender classification
# Additional values appended to the inherited set.
attributes:
O:
alias: OTHER
description: Other / non-binary
U:
alias: UNKNOWN
description: Not specified
| Field | Type | Description |
|---|---|---|
base | string | Name of a parent EnumType to extend. |
attributes | Record<string, ValueInfo> | Map of accepted wire values to their metadata. |
ValueInfo
| Field | Type | Description |
|---|---|---|
alias | string | Human-readable key (e.g. the enum key MALE for value "M"). |
description | string | Description of this value. |
ComplexType
A structured object with named fields.
- TypeScript
- JSON
- YAML
interface ComplexType extends DataTypeBase {
kind: 'ComplexType';
// Name of the parent ComplexType to inherit fields from.
// → See: Complex Types > Inheritance
base?: string;
// Named field definitions.
// → See: Field
// Example: { city: { type: 'string', required: true }, street: { type: 'string' } }
fields?: Record<string, Field>;
// Policy for properties not declared as fields.
// false | undefined → strip silently (default)
// true → allow any additional property
// 'string' → additional properties must match this type name
// ['error'] → reject with a validation error
// ['error', msg] → reject with a custom message
additionalFields?: boolean | string | ['error'] | ['error', string];
// Field name used as the primary key for this type.
// Example: '_id'
keyField?: string;
// Field used to identify the concrete type in a union. → See: Complex Types > Discriminator
discriminatorField?: string;
// Value of discriminatorField that maps to this type.
discriminatorValue?: string;
}
interface Field {
// Data type name or inline type definition. → See: Type Definitions
// Example: 'string' | 'email' | 'Address' | { kind: 'EnumType', attributes: { ... } }
type?: string | DataType;
// Human-readable field description.
description?: string;
// Field must be present on create operations.
required?: boolean;
// Field cannot be modified after creation.
readonly?: boolean;
// Accepted on write, never returned on read.
writeonly?: boolean;
// Excluded from results unless explicitly requested.
exclusive?: boolean;
// Default value when the field is absent.
default?: any;
// Field is locked to this value and ignores input.
fixed?: any;
// Marks the field deprecated, optionally with a migration message.
// Example: 'Use phoneNumbers instead'
deprecated?: boolean | string;
// Nested entity within the parent document.
isNestedEntity?: boolean;
// Key field name when the field holds an array of ComplexType items.
keyField?: string;
// Marks the field as a localization candidate.
localization?: boolean;
// Example values shown in schema documentation.
// Example: ['john@example.com', 'jane@example.com']
examples?: any[] | Record<string, any>;
}
{
"kind": "ComplexType",
"description": "A postal address",
"base": "Record",
"keyField": "_id",
"additionalFields": false,
"fields": {
"city": { "type": "string", "required": true },
"countryCode": { "type": "string", "required": true },
"street": { "type": "string" },
"zipCode": { "type": "string" }
}
}
kind: ComplexType
# Human-readable description of the type.
description: A postal address
# Name of the parent ComplexType to inherit fields from. → See: Complex Types > Inheritance
base: Record
# Field name used as the primary key.
keyField: _id
# Policy for properties not declared as fields.
# false → strip silently (default) | true → allow any | ['error'] → reject with error
additionalFields: false
# Named field definitions.
fields:
city:
# Data type name or inline definition. → See: Type Definitions
type: string
# Field must be present on create operations.
required: true
countryCode:
type: string
required: true
street:
# Optional field — no required: true
type: string
zipCode:
type: string
| Field | Type | Description |
|---|---|---|
base | string | Name of the parent ComplexType. |
fields | Record<string, Field> | Named field definitions. |
additionalFields | boolean | string | ['error'] | ['error', string] | Policy for properties not declared as fields. |
keyField | string | Field name used as the primary key. |
discriminatorField | string | Field used to identify the concrete type in a union. |
discriminatorValue | string | Value of discriminatorField that maps to this type. |
Field
| Field | Type | Description |
|---|---|---|
type | string | DataType | Field data type name or inline type definition. |
description | string | Field description. |
required | boolean | Must be present. |
readonly | boolean | Cannot be modified after creation. |
writeonly | boolean | Accepted on write, never returned on read. |
exclusive | boolean | Excluded from results unless explicitly requested. |
default | any | Default value when absent. |
fixed | any | Locked value — ignores input. |
deprecated | boolean | string | Marks the field deprecated, optionally with a message. |
isNestedEntity | boolean | Nested entity within the parent document. |
keyField | string | Key field name for ComplexType array items. |
localization | boolean | Localization candidate. |
examples | any[] | Record<string, any> | Example values. |
ArrayType
A typed array wrapper.
- TypeScript
- JSON
- YAML
interface ArrayType extends DataTypeBase {
kind: 'ArrayType';
// Element type name or inline type definition. → See: Type Definitions
// Example: 'string' | 'Customer' | { kind: 'EnumType', attributes: { ... } }
type?: string | DataType;
// Minimum number of elements (inclusive).
minOccurs?: number;
// Maximum number of elements (inclusive).
maxOccurs?: number;
}
{
"kind": "ArrayType",
"type": "string",
"minOccurs": 1,
"maxOccurs": 20
}
kind: ArrayType
# Element type name or inline type definition. → See: Type Definitions
type: string
# Minimum number of elements (inclusive).
minOccurs: 1
# Maximum number of elements (inclusive).
maxOccurs: 20
| Field | Type | Description |
|---|---|---|
type | string | DataType | Element type name or inline type definition. |
minOccurs | number | Minimum number of elements. |
maxOccurs | number | Maximum number of elements. |
MappedType
A type derived from another by picking, omitting, or changing the optionality of its fields.
- TypeScript
- JSON
- YAML
interface MappedType extends DataTypeBase {
kind: 'MappedType';
// Source type to transform. Required.
// → See: Mapped Types
base: string | DataType;
// Keep only these fields (PickType equivalent). → See: Mapped Types > PickType
// Example: ['_id', 'givenName', 'familyName']
pick?: string[];
// Remove these fields (OmitType equivalent). → See: Mapped Types > OmitType
// Example: ['passwordHash', 'internalScore']
omit?: string[];
// Make all or listed fields optional (PartialType equivalent). → See: Mapped Types > PartialType
// true → all fields optional | string[] → only listed fields
partial?: boolean | string[];
// Make all or listed fields required (RequiredType equivalent). → See: Mapped Types > RequiredType
// true → all fields required | string[] → only listed fields
required?: boolean | string[];
// Discriminator field override.
discriminatorField?: string;
// Discriminator value override.
discriminatorValue?: string;
}
{
"kind": "MappedType",
"base": "Customer",
"pick": ["_id", "givenName", "familyName"],
"partial": true
}
kind: MappedType
# Source type to transform. Required. → See: Mapped Types
base: Customer
# Keep only these fields (PickType equivalent). → See: Mapped Types > PickType
pick:
- _id
- givenName
- familyName
# Make all picked fields optional (PartialType equivalent). → See: Mapped Types > PartialType
# Use a list to make only specific fields optional: [email, phone]
partial: true
# Remove these fields instead (OmitType equivalent). → See: Mapped Types > OmitType
# omit:
# - internalScore
# Force specific fields required (RequiredType equivalent). → See: Mapped Types > RequiredType
# required:
# - _id
| Field | Type | Description |
|---|---|---|
base | string | DataType | Source type to transform. Required. |
pick | string[] | Keep only these fields. |
omit | string[] | Remove these fields. |
partial | boolean | string[] | Make all (or listed) fields optional. |
required | boolean | string[] | Make all (or listed) fields required. |
discriminatorField | string | Discriminator field override. |
discriminatorValue | string | Discriminator value override. |
MixinType
A composite type that merges fields from multiple base types.
- TypeScript
- JSON
- YAML
interface MixinType extends DataTypeBase {
kind: 'MixinType';
// Ordered list of base types to merge.
// Fields are merged in array order — last type wins on name conflicts.
// → See: Mixin Types > Field Merging
// Example: ['Timestamped', 'SoftDeletable']
types: (string | DataType)[];
}
{
"kind": "MixinType",
"types": ["Timestamped", "SoftDeletable"]
}
kind: MixinType
# Ordered list of base types to merge.
# Fields are merged in array order — last type wins on name conflicts.
# → See: Mixin Types > Field Merging
types:
- Timestamped
- SoftDeletable
| Field | Type | Description |
|---|---|---|
types | (string | DataType)[] | Ordered list of base types to merge. Last-write-wins on field name conflicts. |
UnionType
A type that accepts one of several possible types at runtime.
- TypeScript
- JSON
- YAML
interface UnionType extends DataTypeBase {
kind: 'UnionType';
// List of accepted types.
// Each type should declare a discriminatorValue matching a value of the discriminator field.
// → See: Complex Types > Discriminator
// Example: ['Dog', 'Cat']
types: (string | DataType)[];
// Field name used to select the concrete type at decode time.
// Example: 'kind'
discriminator?: string;
}
{
"kind": "UnionType",
"discriminator": "kind",
"types": ["Dog", "Cat"]
}
kind: UnionType
# Field name used to select the concrete type at decode time.
# Each listed type must declare a matching discriminatorValue. → See: Complex Types > Discriminator
discriminator: kind
# List of accepted types.
types:
- Dog
- Cat
| Field | Type | Description |
|---|---|---|
types | (string | DataType)[] | List of accepted types. |
discriminator | string | Field name used to select the concrete type at decode time. |
References
The references field links external OPRA documents into the current document under a namespace alias. Linked types can be referenced as namespace:TypeName.
- TypeScript
- JSON
- YAML
interface DocumentReference {
// URL where the referenced document can be fetched.
// Example: 'https://api.example.com/customer-models/opra.json'
url?: string;
// Metadata snapshot of the referenced document. → See: Document Info
// Example: { title: 'Customer Models', version: '1.0' }
info?: DocumentInfo;
}
// Usage: types from namespace 'cm' are referenced as 'cm:Customer'
const references: Record<string, DocumentReference> = {
cm: {
url: 'https://api.example.com/customer-models/opra.json',
info: { title: 'Customer Models', version: '1.0' },
},
};
{
"references": {
"cm": {
"url": "https://api.example.com/customer-models/opra.json",
"info": {
"title": "Customer Models",
"version": "1.0"
}
}
}
}
references:
# Namespace alias. Types from this document are referenced as "cm:TypeName".
cm:
# URL where the referenced document can be fetched.
url: https://api.example.com/customer-models/opra.json
# Metadata snapshot of the referenced document. → See: Document Info
info:
title: Customer Models
version: "1.0"
DocumentReference
| Field | Type | Description |
|---|---|---|
url | string | URL where the referenced document can be fetched. |
info | DocumentInfo | Metadata snapshot of the referenced document. |
HTTP API Schema
The api field holds the HTTP API definition when transport is "http".
- TypeScript
- JSON
- YAML
interface HttpApi {
// Transport identifier.
transport: 'http';
// API name.
// Example: 'CustomerApi'
name: string;
// Human-readable description.
description?: string;
// Base URL path for all controllers.
// Example: '/api'
url?: string;
// Named controller definitions. → See: HttpController
// Example: { Customers: { kind: 'HttpController', path: '/customers', operations: { ... } } }
controllers: Record<string, HttpController>;
}
{
"api": {
"transport": "http",
"name": "CustomerApi",
"description": "Customer management API",
"url": "/api",
"controllers": { }
}
}
api:
# Transport identifier.
transport: http
# API name.
name: CustomerApi
# Human-readable description.
description: Customer management API
# Base URL path prepended to all controller paths.
url: /api
# Named controller definitions. → See: HttpController
controllers:
HttpController
Groups related operations under a shared path. Controllers can be nested.
- TypeScript
- JSON
- YAML
interface HttpController {
kind: 'HttpController';
// Human-readable description.
description?: string;
// URL path segment appended to the parent path.
// Example: '/customers'
path?: string;
// Parameters shared by all operations in this controller. → See: HttpParameter
// Example: [{ name: 'tenantId', location: 'header', type: 'string', required: true }]
parameters?: HttpParameter[];
// Named operation definitions. → See: HttpOperation
// Example: { Get: { kind: 'HttpOperation', method: 'GET', ... } }
operations?: Record<string, HttpOperation>;
// Nested child controllers (same structure, recursive). → See: HttpController
// Example: { Orders: { kind: 'HttpController', path: '/:id/orders', ... } }
controllers?: Record<string, HttpController>;
// Local type definitions scoped to this controller. → See: Type Definitions
types?: Record<string, DataType>;
}
{
"Customers": {
"kind": "HttpController",
"description": "Customer resource",
"path": "/customers",
"parameters": [ ],
"operations": { },
"controllers": { }
}
}
Customers:
kind: HttpController
# Human-readable description.
description: Customer resource
# URL path segment appended to the parent path.
path: /customers
# Parameters shared by all operations in this controller. → See: HttpParameter
parameters:
# Named operation definitions. → See: HttpOperation
operations:
# Nested child controllers (same structure, recursive).
controllers:
# Local type definitions scoped to this controller. → See: Type Definitions
types:
| Field | Type | Description |
|---|---|---|
kind | "HttpController" | Always "HttpController". |
description | string | Human-readable description. |
path | string | URL path segment appended to the parent path. |
parameters | HttpParameter[] | Parameters shared by all operations in this controller. |
operations | Record<string, HttpOperation> | Named operation definitions. |
controllers | Record<string, HttpController> | Nested child controllers. |
types | Record<string, DataType> | Local type definitions scoped to this controller. |
HttpOperation
A single HTTP endpoint.
- TypeScript
- JSON
- YAML
interface HttpOperation {
kind: 'HttpOperation';
// HTTP method.
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'SEARCH';
// URL path segment appended to the controller path unless mergePath is true.
// Example: '/:id'
path?: string;
// When true, merges path into the parent instead of appending.
mergePath?: boolean;
// Human-readable description.
description?: string;
// Operation-level parameters. → See: HttpParameter
// Example: [{ name: 'id', location: 'path', type: 'number', required: true }]
parameters?: HttpParameter[];
// Request body definition. → See: HttpRequestBody
// Example: { required: true, content: [{ contentType: 'application/json', type: 'Customer' }] }
requestBody?: HttpRequestBody;
// Response definitions. → See: HttpOperationResponse
// Example: [{ statusCode: 200, contentType: 'application/json', type: 'Customer' }]
responses?: HttpOperationResponse[];
// Local type definitions scoped to this operation. → See: Type Definitions
types?: Record<string, DataType>;
}
{
"Get": {
"kind": "HttpOperation",
"method": "GET",
"path": "/:id",
"description": "Retrieve a customer by ID",
"parameters": [ ],
"requestBody": { },
"responses": [ ]
}
}
Get:
kind: HttpOperation
# HTTP method: GET | POST | PUT | PATCH | DELETE | HEAD | OPTIONS | SEARCH
method: GET
# URL path segment appended to the controller path.
path: /:id
# Human-readable description.
description: Retrieve a customer by ID
# Operation-level parameters. → See: HttpParameter
parameters:
# Request body definition. → See: HttpRequestBody
requestBody:
# Response definitions. → See: HttpOperationResponse
responses:
# Local type definitions scoped to this operation. → See: Type Definitions
types:
| Field | Type | Description |
|---|---|---|
kind | "HttpOperation" | Always "HttpOperation". |
method | string | HTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, SEARCH. |
path | string | URL path segment. Appended to the controller path unless mergePath is true. |
mergePath | boolean | Merge path into the parent instead of appending. |
description | string | Human-readable description. |
parameters | HttpParameter[] | Operation-level parameters. |
requestBody | HttpRequestBody | Request body definition. |
responses | HttpOperationResponse[] | Response definitions. |
types | Record<string, DataType> | Local type definitions scoped to this operation. |
HttpParameter
A query, path, header, or cookie parameter.
- TypeScript
- JSON
- YAML
interface HttpParameter {
// Parameter name.
// Example: 'id'
name: string;
// Parameter location.
location: 'query' | 'path' | 'header' | 'cookie';
// Parameter data type name or inline definition. → See: Type Definitions
// Example: 'number' | 'string' | { kind: 'EnumType', attributes: { ... } }
type?: string | DataType;
// Parameter must be provided.
required?: boolean;
// Default value when the parameter is absent.
default?: any;
// Marks the parameter deprecated, optionally with a migration message.
deprecated?: boolean | string;
// Identifies this as the primary key parameter.
keyParam?: boolean;
// Separator character for array-valued query parameters.
// Example: ',' for comma-separated values
arraySeparator?: string;
// Human-readable description.
description?: string;
}
{
"name": "id",
"location": "path",
"type": "number",
"required": true
}
# Parameter name.
name: id
# Parameter location: query | path | header | cookie
location: path
# Data type name or inline definition. → See: Type Definitions
type: number
# Parameter must be provided.
required: true
# Default value when the parameter is absent.
# default: 1
# Marks the parameter deprecated, optionally with a migration message.
# deprecated: Use customerId instead
# Identifies this as the primary key parameter.
# keyParam: true
# Separator character for array-valued query parameters.
# arraySeparator: ","
| Field | Type | Description |
|---|---|---|
name | string | Parameter name. |
location | string | "query", "path", "header", or "cookie". |
type | string | DataType | Parameter data type. |
required | boolean | Parameter must be provided. |
default | any | Default value when absent. |
deprecated | boolean | string | Marks the parameter deprecated. |
keyParam | boolean | Identifies this as the primary key parameter. |
arraySeparator | string | Separator character for array-valued query parameters. |
description | string | Human-readable description. |
HttpRequestBody
The request body accepted by an operation.
- TypeScript
- JSON
- YAML
interface HttpRequestBody {
// Body must be present.
required?: boolean;
// Treat all fields as optional.
// true → top-level fields optional | 'deep' → recursively optional (useful for PATCH)
partial?: boolean | 'deep';
// Allow patch operator expressions (e.g. $set, $unset) in the body.
allowPatchOperators?: boolean;
// Maximum allowed body size in bytes.
// Example: 1048576 (1 MB)
maxContentSize?: number;
// Accepted media type definitions. → See: HttpMediaType
// Example: [{ contentType: 'application/json', type: 'Customer' }]
content: HttpMediaType[];
}
{
"required": true,
"content": [
{
"contentType": "application/json",
"type": "Customer"
}
]
}
# Body must be present.
required: true
# Treat all fields as optional (true = top-level, deep = recursive). Useful for PATCH.
# partial: true
# Allow patch operator expressions (e.g. $set, $unset) in the body.
# allowPatchOperators: true
# Maximum allowed body size in bytes.
# maxContentSize: 1048576
# Accepted media type definitions. → See: HttpMediaType
content:
- # MIME type of the accepted content.
contentType: application/json
# Data type of the body. → See: Type Definitions
type: Customer
| Field | Type | Description |
|---|---|---|
required | boolean | Body must be present. |
partial | boolean | "deep" | Treat all fields as optional (for PATCH operations). |
allowPatchOperators | boolean | Allow patch operator expressions in the body. |
maxContentSize | number | Maximum allowed body size in bytes. |
content | HttpMediaType[] | Accepted media type definitions. |
HttpMediaType
Defines a single accepted or returned media type.
- TypeScript
- JSON
- YAML
interface HttpMediaType {
// MIME type or range. Omit to accept any content type.
// Example: 'application/json' | 'multipart/form-data'
contentType?: string | string[];
// Data type of the body. → See: Type Definitions
// Example: 'Customer' | { kind: 'ComplexType', fields: { ... } }
type?: string | DataType;
// Content encoding.
// Example: 'gzip'
contentEncoding?: string;
// Inline example value.
example?: string;
// Named example values.
// Example: { minimal: '{"name":"Jane"}', full: '{"name":"Jane","email":"..."}' }
examples?: Record<string, string>;
// Multipart field definitions (for multipart/form-data uploads).
multipartFields?: HttpMultipartField[];
// Maximum number of non-file fields.
maxFields?: number;
// Maximum total size of non-file fields in bytes.
maxFieldsSize?: number;
// Maximum number of uploaded files.
maxFiles?: number;
// Maximum size per file in bytes.
// Example: 10485760 (10 MB)
maxFileSize?: number;
// Maximum combined size of all files in bytes.
// Example: 52428800 (50 MB)
maxTotalFileSize?: number;
// Minimum size per file in bytes.
minFileSize?: number;
}
{
"contentType": "application/json",
"type": "Customer"
}
# MIME type or range. Omit to accept any content type.
contentType: application/json
# Data type of the body. → See: Type Definitions
type: Customer
# Content encoding. Example: gzip
# contentEncoding: gzip
# Inline example value.
# example: '{"givenName":"Jane"}'
For multipart file uploads:
- TypeScript
- JSON
- YAML
const uploadBody: HttpMediaType = {
contentType: 'multipart/form-data',
maxFields: 10,
maxFieldsSize: 65536,
maxFiles: 5,
maxFileSize: 10485760, // 10 MB per file
maxTotalFileSize: 52428800, // 50 MB total
minFileSize: 1,
};
{
"contentType": "multipart/form-data",
"maxFiles": 5,
"maxFileSize": 10485760,
"maxTotalFileSize": 52428800
}
# MIME type for multipart file uploads.
contentType: multipart/form-data
# Maximum number of non-file fields.
maxFields: 10
# Maximum total size of non-file fields in bytes.
maxFieldsSize: 65536
# Maximum number of uploaded files.
maxFiles: 5
# Maximum size per individual file in bytes. Example: 10485760 = 10 MB
maxFileSize: 10485760
# Maximum combined size of all uploaded files in bytes. Example: 52428800 = 50 MB
maxTotalFileSize: 52428800
# Minimum size per individual file in bytes.
minFileSize: 1
| Field | Type | Description |
|---|---|---|
contentType | string | string[] | MIME type or range. |
type | string | DataType | Data type of the body. |
contentEncoding | string | Content encoding. |
example | string | Inline example value. |
examples | Record<string, string> | Named example values. |
multipartFields | HttpMultipartField[] | Multipart field definitions. |
maxFields | number | Maximum number of non-file fields. |
maxFieldsSize | number | Maximum total size of non-file fields in bytes. |
maxFiles | number | Maximum number of uploaded files. |
maxFileSize | number | Maximum size per file in bytes. |
maxTotalFileSize | number | Maximum combined size of all files in bytes. |
minFileSize | number | Minimum size per file in bytes. |
HttpOperationResponse
A response returned by an operation. Extends HttpMediaType with status code and response-specific fields.
- TypeScript
- JSON
- YAML
interface HttpOperationResponse extends HttpMediaType {
// HTTP status code(s) this response applies to.
// Single code: 200 | Range string: '2xx' | List: [200, 201]
statusCode: number | string | (number | string)[];
// Response header parameters. → See: HttpParameter
// Example: [{ name: 'X-Request-Id', location: 'header', type: 'string' }]
parameters?: HttpParameter[];
// Response fields may be partially present.
partial?: boolean | 'deep';
}
{
"statusCode": 200,
"contentType": "application/json",
"type": "Customer"
}
# HTTP status code(s) this response applies to.
# Single code: 200 | Range string: "2xx" | List: [200, 201]
statusCode: 200
# MIME type of the response body.
contentType: application/json
# Data type of the response body. → See: Type Definitions
type: Customer
# Response fields may be partially present (true = top-level, deep = recursive).
# partial: true
# Response header parameters. → See: HttpParameter
# parameters:
| Field | Type | Description |
|---|---|---|
statusCode | number | string | (number | string)[] | HTTP status code(s) this response applies to (e.g. 200, "2xx"). |
parameters | HttpParameter[] | Response header parameters. |
partial | boolean | "deep" | Response fields may be partially present. |
Message Queue API Schema
The api field holds the MQ API definition when transport is "mq".
- TypeScript
- JSON
- YAML
interface MQApi {
// Transport identifier.
transport: 'mq';
// API name.
// Example: 'CustomerEvents'
name: string;
// Messaging platform.
// Example: 'Kafka' | 'RabbitMQ'
platform: string;
// Human-readable description.
description?: string;
// Named controller definitions. → See: MQController
// Example: { CustomerEvents: { kind: 'MQController', operations: { ... } } }
controllers: Record<string, MQController>;
}
{
"api": {
"transport": "mq",
"name": "CustomerEvents",
"platform": "Kafka",
"description": "Customer domain events",
"controllers": { }
}
}
api:
# Transport identifier.
transport: mq
# API name.
name: CustomerEvents
# Messaging platform. Example: Kafka | RabbitMQ
platform: Kafka
# Human-readable description.
description: Customer domain events
# Named controller definitions. → See: MQController
controllers:
MQController
Groups related message operations.
- TypeScript
- JSON
- YAML
interface MQController {
kind: 'MQController';
// Human-readable description.
description?: string;
// Message headers shared by all operations.
// Example: [{ name: 'correlationId', type: 'string' }]
headers?: MQHeader[];
// Named operation definitions. → See: MQOperation
// Example: { CustomerCreated: { kind: 'MQOperation', channel: 'customer.created', type: 'CustomerCreatedEvent' } }
operations?: Record<string, MQOperation>;
// Local type definitions scoped to this controller. → See: Type Definitions
types?: Record<string, DataType>;
}
{
"CustomerEvents": {
"kind": "MQController",
"description": "Customer event handlers",
"headers": [ ],
"operations": { }
}
}
CustomerEvents:
kind: MQController
# Human-readable description.
description: Customer event handlers
# Message headers shared by all operations.
headers:
# Named operation definitions. → See: MQOperation
operations:
# Local type definitions scoped to this controller. → See: Type Definitions
types:
| Field | Type | Description |
|---|---|---|
kind | "MQController" | Always "MQController". |
description | string | Human-readable description. |
headers | MQHeader[] | Headers shared by all operations. |
operations | Record<string, MQOperation> | Named operation definitions. |
types | Record<string, DataType> | Local type definitions. |
MQOperation
A single message channel subscription or publication.
- TypeScript
- JSON
- YAML
interface MQOperation {
kind: 'MQOperation';
// Channel name or pattern this operation listens on.
// Example: 'customer.created' | ['customer.created', 'customer.updated']
channel: string | string[];
// Message payload type name or inline definition. → See: Type Definitions
// Example: 'CustomerCreatedEvent'
type: string | DataType;
// Message key type (for keyed messages, e.g. Kafka partition key).
// Example: 'string'
keyType?: string | DataType;
// Operation-level message headers.
headers?: MQHeader[];
// Human-readable description.
description?: string;
// Optional response message definition. → See: MQOperationResponse
// Example: { channel: 'customer.created.ack', type: 'Ack' }
response?: MQOperationResponse;
// Local type definitions scoped to this operation. → See: Type Definitions
types?: Record<string, DataType>;
}
interface MQOperationResponse {
// Response channel name or pattern.
// Example: 'customer.created.ack'
channel?: string | string[];
// Response payload type name or inline definition. → See: Type Definitions
type: string | DataType;
// Response message key type.
keyType?: string | DataType;
// Response message headers.
headers?: MQHeader[];
// Human-readable description.
description?: string;
}
{
"CustomerCreated": {
"kind": "MQOperation",
"channel": "customer.created",
"type": "CustomerCreatedEvent",
"response": {
"channel": "customer.created.ack",
"type": "Ack"
}
}
}
CustomerCreated:
kind: MQOperation
# Channel name, pattern, or list of patterns this operation listens on.
channel: customer.created
# Message payload type name or inline definition. → See: Type Definitions
type: CustomerCreatedEvent
# Message key type for keyed messages (e.g. Kafka partition key).
# keyType: string
# Operation-level message headers.
# headers:
# Optional response message sent after processing.
response:
# Response channel name or pattern.
channel: customer.created.ack
# Response payload type. → See: Type Definitions
type: Ack
| Field | Type | Description |
|---|---|---|
kind | "MQOperation" | Always "MQOperation". |
channel | string | string[] | Channel name or pattern this operation listens on. |
type | string | DataType | Message payload type. |
keyType | string | DataType | Message key type (for keyed messages, e.g. Kafka). |
headers | MQHeader[] | Operation-level message headers. |
description | string | Human-readable description. |
response | MQOperationResponse | Optional response message definition. |
types | Record<string, DataType> | Local type definitions. |
WebSocket API Schema
The api field holds the WebSocket API definition when transport is "ws".
- TypeScript
- JSON
- YAML
interface WSApi {
// Transport identifier.
transport: 'ws';
// API name.
// Example: 'NotificationApi'
name: string;
// WebSocket platform.
// Example: 'Socketio'
platform?: string;
// Human-readable description.
description?: string;
// Named controller definitions. → See: WSController
// Example: { Notifications: { kind: 'WSController', operations: { ... } } }
controllers: Record<string, WSController>;
}
{
"api": {
"transport": "ws",
"name": "NotificationApi",
"platform": "Socketio",
"description": "Real-time notification events",
"controllers": { }
}
}
api:
# Transport identifier.
transport: ws
# API name.
name: NotificationApi
# WebSocket platform. Example: Socketio
platform: Socketio
# Human-readable description.
description: Real-time notification events
# Named controller definitions. → See: WSController
controllers:
WSController
Groups related WebSocket event handlers.
- TypeScript
- JSON
- YAML
interface WSController {
kind: 'WSController';
// Human-readable description.
description?: string;
// Named operation definitions. → See: WSOperation
// Example: { OnNotification: { kind: 'WSOperation', event: 'notification', arguments: ['Notification'] } }
operations?: Record<string, WSOperation>;
// Local type definitions scoped to this controller. → See: Type Definitions
types?: Record<string, DataType>;
}
{
"Notifications": {
"kind": "WSController",
"description": "Notification handlers",
"operations": { }
}
}
Notifications:
kind: WSController
# Human-readable description.
description: Notification handlers
# Named operation definitions. → See: WSOperation
operations:
# Local type definitions scoped to this controller. → See: Type Definitions
types:
| Field | Type | Description |
|---|---|---|
kind | "WSController" | Always "WSController". |
description | string | Human-readable description. |
operations | Record<string, WSOperation> | Named operation definitions. |
types | Record<string, DataType> | Local type definitions. |
WSOperation
A single WebSocket event handler.
- TypeScript
- JSON
- YAML
interface WSOperation {
kind: 'WSOperation';
// WebSocket event name this operation handles.
// Example: 'notification'
event: string;
// Ordered list of argument types. → See: Type Definitions
// Example: ['Notification'] | ['string', 'NotificationOptions']
arguments?: (string | DataType)[];
// Response type returned to the caller. → See: Type Definitions
// Example: 'Ack' | { kind: 'ComplexType', fields: { success: { type: 'boolean' } } }
response?: string | DataType;
// Human-readable description.
description?: string;
// Local type definitions scoped to this operation. → See: Type Definitions
types?: Record<string, DataType>;
}
{
"OnNotification": {
"kind": "WSOperation",
"event": "notification",
"arguments": ["Notification"],
"response": "Ack"
}
}
OnNotification:
kind: WSOperation
# WebSocket event name this operation handles.
event: notification
# Ordered list of argument types. → See: Type Definitions
arguments:
- Notification
# Response type returned to the caller. → See: Type Definitions
response: Ack
# Human-readable description.
description: Handle incoming notification events
# Local type definitions scoped to this operation. → See: Type Definitions
# types:
| Field | Type | Description |
|---|---|---|
kind | "WSOperation" | Always "WSOperation". |
event | string | Event name this operation handles. |
arguments | (string | DataType)[] | Ordered list of argument types. |
response | string | DataType | Response type returned to the caller. |
description | string | Human-readable description. |
types | Record<string, DataType> | Local type definitions. |