{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openappdefinition.org/schema/0.2/common.schema.json",
  "title": "OAD 0.2 shared definitions",
  "description": "Definitions shared by the Open App Definition 0.2 document schemas. This document validates nothing on its own; other schemas reference its $defs. The annotation keyword x-oad-kind marks strings and values that hold expressions, paths or dynamic values, so tools can find them by walking a document alongside its schema.",
  "$defs": {
    "name": {
      "title": "name",
      "description": "A name: the key of a state entry, action, rule, flow, code module, capability, grant, part, role, view, view state entry, flow state, event, intent, field, slot, token or variant, a local name bound by as, let or indexAs, or a catalog or definition alias. Starts with a lowercase ASCII letter, followed by ASCII letters and digits. It must not be one of the reserved words true, false, null and in.",
      "type": "string",
      "pattern": "^(?!(?:true|false|null|in)$)[a-z][a-zA-Z0-9]*$"
    },
    "localName": {
      "title": "local name",
      "description": "A local name bound by as (on a call, run, code or each step, or a node's each), by a let step, or by indexAs (on an each step or a node's each). A name that is also not one of the expression root names env, state, sources, capabilities, grants, flows, parts, user, input, output, event, view, item, index and error.",
      "type": "string",
      "pattern": "^(?!(?:true|false|null|in|env|state|sources|capabilities|grants|flows|parts|user|input|output|event|view|item|index|error)$)[a-z][a-zA-Z0-9]*$"
    },
    "typeName": {
      "title": "type name",
      "description": "The name of a type defined in types. Starts with an uppercase ASCII letter, followed by ASCII letters and digits.",
      "type": "string",
      "pattern": "^[A-Z][a-zA-Z0-9]*$"
    },
    "reverseDnsId": {
      "title": "reverse-DNS identifier",
      "description": "A globally unique identifier in reverse-DNS form: lowercase, at least two dot-separated segments, each made of a-z, 0-9 and hyphen.",
      "type": "string",
      "pattern": "^[a-z0-9-]+(?:\\.[a-z0-9-]+)+$"
    },
    "specVersion": {
      "title": "spec version",
      "description": "A specification version in MAJOR.MINOR form.",
      "type": "string",
      "pattern": "^(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)$"
    },
    "semver": {
      "title": "semantic version",
      "description": "A Semantic Versioning 2.0.0 version, such as 1.2.0 or 2.0.0-beta.1.",
      "type": "string",
      "pattern": "^(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)(?:-(?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\\+[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*)?$"
    },
    "semverRange": {
      "title": "semantic version range",
      "description": "A range of semantic versions in the conventional range syntax: an exact version, a comparator (^, ~, >, >=, <, <=, =) followed by a full or partial version, partial versions with x or * wildcards, space-separated comparator sets, hyphen ranges, and alternatives joined by ||. For example ^1.2.0, ~0.1.0, >=1.0.0 <2.0.0, 1.x.",
      "type": "string",
      "pattern": "^(?:(?:(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?) - (?:(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?)|(?:<=|>=|<|>|=|\\^|~)?(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?(?: (?:<=|>=|<|>|=|\\^|~)?(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?)*)(?: \\|\\| (?:(?:(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?) - (?:(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?)|(?:<=|>=|<|>|=|\\^|~)?(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?(?: (?:<=|>=|<|>|=|\\^|~)?(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:\\.(?:0|[1-9][0-9]*|[xX*])(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?)*))*$"
    },
    "digest": {
      "title": "digest",
      "description": "A content digest: sha256- followed by the unpadded base64url encoding of a SHA-256 hash, taken over the canonical JSON form (RFC 8785) of a JSON document, or over the bytes of any other resource, such as a code module or a control implementation.",
      "type": "string",
      "pattern": "^sha256-[A-Za-z0-9_-]{43}$"
    },
    "isoDuration": {
      "title": "ISO 8601 duration",
      "description": "An ISO 8601 duration such as P1D, PT1H, P3D or PT0.016S. At least one component is required, T must be followed by a time component, and only seconds may be fractional (up to 9 digits).",
      "type": "string",
      "pattern": "^P(?!$)(?:[0-9]+Y)?(?:[0-9]+M)?(?:[0-9]+W)?(?:[0-9]+D)?(?:T(?=[0-9])(?:[0-9]+H)?(?:[0-9]+M)?(?:[0-9]+(?:\\.[0-9]{1,9})?S)?)?$"
    },
    "datetime": {
      "title": "UTC timestamp",
      "description": "An ISO 8601 (RFC 3339) timestamp in UTC, written with a Z suffix, such as 2026-03-01T12:00:00Z.",
      "type": "string",
      "pattern": "^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]:(?:[0-5][0-9]|60)(?:\\.[0-9]+)?Z$"
    },
    "uri": {
      "title": "absolute URI",
      "description": "An absolute URI with a scheme, such as https://example.com/terms.",
      "type": "string",
      "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:[^\\s]+$"
    },
    "uriReference": {
      "title": "URI reference",
      "description": "A URI or a relative reference, without whitespace.",
      "type": "string",
      "pattern": "^[^\\s]+$"
    },
    "text": {
      "title": "text",
      "description": "Non-empty plain-language text.",
      "type": "string",
      "minLength": 1
    },
    "contractRef": {
      "title": "contract reference",
      "description": "A reference to a contract in a catalog, written alias:contractName, where alias is a key of uses.catalogs. Both parts are names.",
      "type": "string",
      "pattern": "^(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*:(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*$"
    },
    "catalogContractRef": {
      "title": "catalog contract reference",
      "description": "A contract named from inside a catalog: a contract name in the same catalog, or alias:contractName for a contract in a catalog this catalog uses, where alias is a key of its uses.catalogs.",
      "type": "string",
      "pattern": "^(?:(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*:)?(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*$"
    },
    "qualifiedContractRef": {
      "title": "fully qualified contract reference",
      "description": "A contract named by catalog id and contract name, written catalogId:contractName, such as org.openappdefinition.core:button.",
      "type": "string",
      "pattern": "^[a-z0-9-]+(?:\\.[a-z0-9-]+)+:(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*$"
    },
    "scopeName": {
      "title": "scope name",
      "description": "The name of a permission scope defined by a capability contract: one or more names joined by dots, such as transactions.read.",
      "type": "string",
      "pattern": "^(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*(?:\\.(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*)*$"
    },
    "expression": {
      "title": "expression",
      "description": "An expression in the OAD expression language, written without a leading =. Used by fields that are always expressions, such as derive, when, if, allow, where, becomes and each.",
      "type": "string",
      "minLength": 1,
      "pattern": "^(?!=)",
      "x-oad-kind": "expression"
    },
    "path": {
      "title": "path",
      "description": "A reference to a writable location, such as state.form.amount, written without a leading =: an identifier followed by names joined by dots and, where the position allows them, by selectors [field=expression] that pick the first list element whose field equals the expression, as in state.answers[id=item.id].note. Identifiers start with a letter or underscore; the first is not a reserved word (true, false, null, in). A path is at most 10000 code points. This schema checks the names before the first [ only; whether the rest, selectors included, follows the path grammar is checked by validation (expression.syntax).",
      "type": "string",
      "maxLength": 10000,
      "pattern": "^(?!(?:true|false|null|in)(?![A-Za-z0-9_]))[A-Za-z_][A-Za-z0-9_]*(?:\\.[A-Za-z_][A-Za-z0-9_]*)*(?:\\[[\\s\\S]*)?$",
      "x-oad-kind": "path"
    },
    "statePath": {
      "title": "state path",
      "description": "A path into a state entry: state, a dot, the entry name, then optional field names joined by dots. Selectors are not allowed here.",
      "type": "string",
      "$ref": "#/$defs/path",
      "pattern": "^state\\.(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*(?:\\.[A-Za-z_][A-Za-z0-9_]*)*$"
    },
    "writeTarget": {
      "title": "write target",
      "description": "The path a set, append, remove or patch step writes: state.<entry> for a stored entry, view.<entry> for a state entry of the view whose handler holds the step, or item inside the steps of a collection flow, each followed by optional field names and selectors such as state.answers[id=item.id].note.",
      "type": "string",
      "$ref": "#/$defs/path",
      "pattern": "^(?:(?:state|view)\\.(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*|item)(?:[.\\[]|$)"
    },
    "bindTarget": {
      "title": "binding target",
      "description": "The path a node's bind writes and reads: state.<entry> for a stored entry that is not shared, or view.<entry> for a state entry of the view, followed by optional field names and selectors, so a row of a repeated list can bind to its own element (state.answers[id=a.id].note).",
      "type": "string",
      "$ref": "#/$defs/path",
      "pattern": "^(?:state|view)\\.(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*(?:[.\\[]|$)"
    },
    "dynamicValue": {
      "title": "dynamic value",
      "description": "Any JSON value that may contain expressions. A string starting with = is an expression; a string starting with == is a literal string starting with a single =; any other value is a literal. Objects and arrays are walked recursively.",
      "x-oad-kind": "dynamic"
    },
    "typeShorthand": {
      "title": "type shorthand",
      "description": "A type reference in shorthand form: a primitive (string, number, integer, boolean, date, datetime, duration, any), a type name from this document, or alias:TypeName for a type of a catalog named in uses.catalogs, optionally followed by [] for a list and then ? for nullable, such as Transaction[], string? or finance:Transaction[]?.",
      "type": "string",
      "pattern": "^(?:string|number|integer|boolean|date|datetime|duration|any|(?:(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*:)?[A-Z][a-zA-Z0-9]*)(?:\\[\\])?\\??$"
    },
    "jsonSchemaTypeName": {
      "title": "JSON Schema type name",
      "description": "One of the JSON Schema primitive type names.",
      "type": "string",
      "enum": ["string", "number", "integer", "boolean", "object", "array", "null"]
    },
    "typeSchema": {
      "title": "type schema",
      "description": "A JSON Schema (2020-12) object restricted to the keywords type, properties, required, additionalProperties, items, minItems, maxItems, uniqueItems, enum, const, oneOf, format, minimum, maximum, minLength, maxLength, pattern, default, description, title and $ref. A $ref is #/types/Name for a type in the same document, or alias:TypeName for a type of a catalog named in uses.catalogs.",
      "type": "object",
      "properties": {
        "type": {
          "description": "The JSON type or types the value may have.",
          "oneOf": [
            { "$ref": "#/$defs/jsonSchemaTypeName" },
            { "$ref": "#/$defs/jsonSchemaTypeNameList" }
          ]
        },
        "properties": {
          "description": "Schemas for the named properties of an object value.",
          "type": "object",
          "additionalProperties": { "$ref": "#/$defs/typeSchema" }
        },
        "required": {
          "description": "Property names an object value must have.",
          "type": "array",
          "items": { "type": "string" },
          "uniqueItems": true
        },
        "additionalProperties": {
          "description": "Whether, or with what schema, an object value may have properties not listed in properties.",
          "oneOf": [
            { "$ref": "#/$defs/booleanFlag" },
            { "$ref": "#/$defs/typeSchema" }
          ]
        },
        "items": {
          "description": "The schema every element of an array value must satisfy.",
          "$ref": "#/$defs/typeSchema"
        },
        "minItems": {
          "description": "Minimum number of elements of an array value.",
          "type": "integer",
          "minimum": 0
        },
        "maxItems": {
          "description": "Maximum number of elements of an array value.",
          "type": "integer",
          "minimum": 0
        },
        "uniqueItems": {
          "description": "When true, no two elements of an array value are equal.",
          "type": "boolean"
        },
        "enum": {
          "description": "The allowed values.",
          "type": "array",
          "minItems": 1
        },
        "const": {
          "description": "The only allowed value."
        },
        "oneOf": {
          "description": "Alternatives: the value matches exactly one of these schemas. Members should be objects told apart by a const property.",
          "type": "array",
          "items": { "$ref": "#/$defs/typeSchema" },
          "minItems": 2
        },
        "format": {
          "description": "A format: date, date-time, duration or uri.",
          "enum": ["date", "date-time", "duration", "uri"]
        },
        "minimum": {
          "description": "Inclusive lower bound for a number.",
          "type": "number"
        },
        "maximum": {
          "description": "Inclusive upper bound for a number.",
          "type": "number"
        },
        "minLength": {
          "description": "Minimum length of a string.",
          "type": "integer",
          "minimum": 0
        },
        "maxLength": {
          "description": "Maximum length of a string.",
          "type": "integer",
          "minimum": 0
        },
        "pattern": {
          "description": "A pattern a string must match, written in the restricted pattern dialect of the expression language, which matches in linear time. Validation, not this schema, checks that it is in the dialect.",
          "type": "string"
        },
        "default": {
          "description": "The value assumed when none is given."
        },
        "description": {
          "description": "Plain-language description of the value.",
          "type": "string"
        },
        "title": {
          "description": "Short human-readable title.",
          "type": "string"
        },
        "$ref": {
          "description": "A reference to a named type: #/types/Name for a type in this document, or alias:TypeName for a type in a catalog from uses.catalogs.",
          "title": "type schema reference",
          "type": "string",
          "pattern": "^(?:#/types/[A-Z][a-zA-Z0-9]*|(?!(?:true|false|null|in)(?![a-zA-Z0-9]))[a-z][a-zA-Z0-9]*:[A-Z][a-zA-Z0-9]*)$"
        }
      },
      "additionalProperties": false
    },
    "jsonSchemaTypeNameList": {
      "title": "JSON Schema type name list",
      "description": "A non-empty list of distinct JSON Schema primitive type names.",
      "type": "array",
      "items": { "$ref": "#/$defs/jsonSchemaTypeName" },
      "minItems": 1,
      "uniqueItems": true
    },
    "booleanFlag": {
      "title": "boolean",
      "description": "A boolean value.",
      "type": "boolean"
    },
    "typeRef": {
      "title": "type reference",
      "description": "A type reference: a string shorthand or a restricted JSON Schema object. Either may name catalog types as alias:TypeName.",
      "oneOf": [
        { "$ref": "#/$defs/typeShorthand" },
        { "$ref": "#/$defs/typeSchema" }
      ]
    },
    "types": {
      "title": "types",
      "description": "An object of type name to restricted JSON Schema object.",
      "type": "object",
      "propertyNames": { "$ref": "#/$defs/typeName" },
      "additionalProperties": { "$ref": "#/$defs/typeSchema" }
    },
    "field": {
      "title": "field",
      "description": "One named input in a field map: type (required), description, required (default true) and default. A field with a default is optional and may not also set required to true.",
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": {
          "description": "Type reference of the field. Required.",
          "$ref": "#/$defs/typeRef"
        },
        "description": {
          "description": "Plain-language description of the field.",
          "$ref": "#/$defs/text"
        },
        "required": {
          "description": "Whether a value must be supplied. Defaults to true.",
          "type": "boolean"
        },
        "default": {
          "description": "A literal JSON value used when the field is absent. A field with a default is optional."
        }
      },
      "additionalProperties": false,
      "dependentSchemas": {
        "default": {
          "properties": {
            "required": {
              "description": "A field with a default is not required.",
              "const": false
            }
          }
        }
      }
    },
    "fieldMap": {
      "title": "field map",
      "description": "Named inputs, keyed by field name: action input, view input and code module input in a definition; capability config, operation input, event payloads and control outputs in a catalog.",
      "type": "object",
      "propertyNames": { "$ref": "#/$defs/name" },
      "additionalProperties": { "$ref": "#/$defs/field" }
    },
    "versionedReference": {
      "title": "versioned reference",
      "description": "A reference to a separately versioned document by id and semantic version range.",
      "type": "object",
      "required": ["id", "version"],
      "properties": {
        "id": {
          "description": "The referenced document's reverse-DNS id.",
          "$ref": "#/$defs/reverseDnsId"
        },
        "version": {
          "description": "The semantic version range the reference accepts.",
          "$ref": "#/$defs/semverRange"
        }
      },
      "additionalProperties": false
    },
    "extensions": {
      "title": "extensions",
      "description": "Vendor extensions, keyed by a reverse-DNS namespace such as com.vendor.feature. The one extension point of a definition. Values are objects whose contents the namespace owner defines. Hosts ignore namespaces they do not understand.",
      "type": "object",
      "propertyNames": { "$ref": "#/$defs/reverseDnsId" },
      "additionalProperties": {
        "description": "The extension's content, defined by the namespace owner.",
        "type": "object"
      }
    }
  }
}
