{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/insuremo-com/json-schema/insuremo-com-comm-context-definition-save-request-schema.json",
  "title": "CommContextDefinitionSaveRequest",
  "description": "Create or save a context definition. Replacement clears omitted optional fields including Contexts and Variables; omitted SamplePayload preserves the stored original and explicit null clears it.",
  "x-generated": "2026-12-02",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/insuremo-com-connecthub-openapi.yml#/components/schemas/CommContextDefinitionSaveRequest",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "Contexts": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/CommContextAliasInput"
      },
      "description": "Alias-to-configuration object map. Each object contains Path: a supported JSONPath rooted at $. A missing result is diagnostic; multiple results or a non-object result fail. Supports field/bracket keys, fixed indices, wildcards and comparison filters. Recursive descent, scripts, functions and regex filters are rejected.",
      "writeOnly": true
    },
    "DefinitionCode": {
      "type": "string",
      "description": "Context definition code. Required for every create/save request; immutable after creation.",
      "maxLength": 40,
      "pattern": "[A-Z][A-Z0-9_]{2,39}",
      "writeOnly": true
    },
    "DefinitionId": {
      "type": "integer",
      "format": "int64",
      "description": "Omit or send null to create. Supply the existing context definition identifier to save it."
    },
    "DefinitionName": {
      "type": "string",
      "description": "Display name of this reusable context definition.",
      "maxLength": 200,
      "writeOnly": true
    },
    "Description": {
      "type": "string",
      "description": "Optional description of the extraction configuration.",
      "maxLength": 500,
      "writeOnly": true
    },
    "ExpectedRevision": {
      "type": "integer",
      "format": "int64",
      "description": "Last read Revision; required when changing an existing resource. Bindings use the owning Definition Revision."
    },
    "GroupId": {
      "type": "integer",
      "format": "int64",
      "description": "Required DataIO publication group identifier; rows of a locked group cannot be published.",
      "writeOnly": true
    },
    "SamplePayload": {
      "type": "object",
      "additionalProperties": true,
      "description": "Optional sample business JSON used for preview and selector warnings. It is not a schema and does not constrain runtime Payload. Keys such as Policy are caller-defined; multiple root keys are allowed.",
      "writeOnly": true
    },
    "Variables": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/CommVariableInput"
      },
      "description": "Name-to-configuration map. Mode defaults to EXTRACT; Source defaults to Payload or is Context.<alias>; Path is JSONPath; ResultMode defaults to SINGLE (LIST preserves match nodes). Optional Required, BlankAsMissing, DefaultValue, MaskOnSend (boolean) and MaskRule (compact string such as {4}*{4}, mandatory when MaskOnSend=true). CONSTANT instead requires native JSON Value and rejects extraction/masking fields. No ValueType coercion. MaskOnSend defaults false; display previews use the current global policy. Required is a preview diagnostic and a send error.",
      "writeOnly": true
    }
  },
  "required": [
    "DefinitionCode",
    "GroupId"
  ],
  "$defs": {
    "CommContextAliasInput": {
      "type": "object",
      "additionalProperties": false,
      "description": "One named context extracted from Payload.",
      "properties": {
        "Path": {
          "type": "string",
          "description": "Supported JSONPath selecting one object."
        }
      },
      "required": [
        "Path"
      ]
    },
    "CommVariableInput": {
      "type": "object",
      "additionalProperties": false,
      "description": "EXTRACT or CONSTANT configuration; native values have no ValueType.",
      "properties": {
        "BlankAsMissing": {
          "type": "boolean",
          "description": "Treat blank text as missing; default false."
        },
        "DefaultValue": {
          "description": "Native JSON fallback for a missing EXTRACT result. Accepts a native JSON string, number, boolean, array, object or null; conditional applicability is validated by the API. For EXTRACT, an explicit null default is rejected; omit DefaultValue when no fallback is needed."
        },
        "MaskOnSend": {
          "type": "boolean",
          "description": "Mask the outbound EXTRACT value independently of global display masking; default false."
        },
        "MaskRule": {
          "type": "string",
          "description": "Compact sending rule, e.g. {4}*{4}; EXTRACT only."
        },
        "Mode": {
          "type": "string",
          "description": "EXTRACT (default) or CONSTANT.",
          "enum": [
            "EXTRACT",
            "CONSTANT"
          ]
        },
        "Path": {
          "type": "string",
          "description": "Supported JSONPath relative to the selected source; EXTRACT only."
        },
        "Required": {
          "type": "boolean",
          "description": "Require a resolved value; default false."
        },
        "ResultMode": {
          "type": "string",
          "description": "SINGLE (default) or LIST; EXTRACT only.",
          "enum": [
            "SINGLE",
            "LIST"
          ]
        },
        "Source": {
          "type": "string",
          "description": "Payload (default) or Context.<alias>; EXTRACT only."
        },
        "Value": {
          "description": "Native JSON literal; must be supplied for CONSTANT, including explicit null. Accepts a native JSON string, number, boolean, array, object or null; conditional applicability is validated by the API."
        }
      }
    }
  }
}