{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/looot/json-schema/looot-create-output-mapping-schema.json",
  "title": "CreateOutputMapping",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/looot-output-mappings-api-openapi.yml#/components/schemas/CreateOutputMapping",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "mappingId",
    "name",
    "definition"
  ],
  "properties": {
    "mappingId": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "definition": {
      "$ref": "#/$defs/OutputMappingDefinition"
    },
    "targetSchema": {}
  },
  "$defs": {
    "OutputMappingDefinition": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode"
      ],
      "properties": {
        "mode": {
          "enum": [
            "raw",
            "canonical",
            "mapped"
          ]
        },
        "expression": {
          "$ref": "#/$defs/OutputMappingExpression"
        }
      }
    },
    "OutputMappingExpression": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "value"
          ],
          "properties": {
            "kind": {
              "const": "literal"
            },
            "value": {}
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "source",
            "path"
          ],
          "properties": {
            "kind": {
              "const": "select"
            },
            "source": {
              "enum": [
                "raw",
                "canonical"
              ]
            },
            "path": {
              "type": "array",
              "maxItems": 32,
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              }
            },
            "required": {
              "type": "boolean",
              "default": true
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "fields"
          ],
          "properties": {
            "kind": {
              "const": "object"
            },
            "fields": {
              "type": "object",
              "additionalProperties": {
                "$ref": "#/$defs/OutputMappingExpression"
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "items"
          ],
          "properties": {
            "kind": {
              "const": "array"
            },
            "items": {
              "type": "array",
              "maxItems": 1000,
              "items": {
                "$ref": "#/$defs/OutputMappingExpression"
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "values"
          ],
          "properties": {
            "kind": {
              "const": "coalesce"
            },
            "values": {
              "type": "array",
              "minItems": 1,
              "maxItems": 64,
              "items": {
                "$ref": "#/$defs/OutputMappingExpression"
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "objects",
            "policy"
          ],
          "properties": {
            "kind": {
              "const": "merge"
            },
            "objects": {
              "type": "array",
              "minItems": 1,
              "maxItems": 64,
              "items": {
                "$ref": "#/$defs/OutputMappingExpression"
              }
            },
            "policy": {
              "enum": [
                "error",
                "prefer_first",
                "prefer_last"
              ]
            }
          }
        }
      ]
    }
  }
}