{
  "openapi": "3.1.0",
  "info": {
    "title": "Recoup API - Data ingestion",
    "version": "1.0.0",
    "description": "Private, versioned data ingestion."
  },
  "servers": [
    {
      "url": "https://api.recoupable.dev"
    }
  ],
  "paths": {
    "/api/ingestion": {
      "get": {
        "summary": "Read an ingestion result",
        "operationId": "readIngestion",
        "description": "Omit action to read a job or stage. Use action only for datasets, imports or records. All responses are private and uncached. The x-recoup-query-schema describes complete valid parameter combinations, including action-specific page sizes.",
        "security": [
          {
            "apiKeyAuth": []
          },
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "description": "Omit to read a job. The three named actions browse an organization dataset.",
            "schema": {
              "type": "string",
              "enum": [
                "datasets",
                "imports",
                "records"
              ]
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "description": "Required for dataset queries and jobs created in organization scope.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "job_id",
            "in": "query",
            "description": "Required for job/stage reads and records.",
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          {
            "name": "stage",
            "in": "query",
            "description": "Omit for job status. Used only without action.",
            "schema": {
              "type": "string",
              "enum": [
                "bronze",
                "silver",
                "gold"
              ]
            }
          },
          {
            "name": "dataset_id",
            "in": "query",
            "description": "Required for imports and records.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum 50 for datasets/imports, 100 for records.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "after",
            "in": "query",
            "description": "Opaque UUID dataset cursor or 64-character import job cursor. Use the next_after returned by the preceding page.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "after_row",
            "in": "query",
            "description": "Record cursor from next_after.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Returns a job, requested stage or one organization catalog page.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Job"
                    },
                    {
                      "$ref": "#/components/schemas/ArtifactResult"
                    },
                    {
                      "$ref": "#/components/schemas/CatalogPage"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, query, or source encoding.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "A valid credential is required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access to the selected scope was denied.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The scoped job or artifact could not be found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The selected version, idempotency key, or artifact conflicts with stored state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "The request, source, or record exceeds its size limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "The caller reached the operation rate limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The operation or its configured infrastructure is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-recoup-query-schema": {
          "examples": [
            {
              "job_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
            }
          ],
          "oneOf": [
            {
              "$ref": "#/components/schemas/JobQuery"
            },
            {
              "$ref": "#/components/schemas/Datasets"
            },
            {
              "$ref": "#/components/schemas/Imports"
            },
            {
              "$ref": "#/components/schemas/Records"
            }
          ]
        }
      },
      "post": {
        "summary": "Process private data",
        "operationId": "operateIngestion",
        "description": "Submit a versioned import, read private artifacts, browse organization datasets, or explicitly deliver one ready output. Standard authenticated MCP uses the same operations. Delegated OAuth excludes this tool.",
        "security": [
          {
            "apiKeyAuth": []
          },
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/Create"
                  },
                  {
                    "$ref": "#/components/schemas/Read"
                  },
                  {
                    "$ref": "#/components/schemas/Artifact"
                  },
                  {
                    "$ref": "#/components/schemas/Deliver"
                  },
                  {
                    "$ref": "#/components/schemas/Datasets"
                  },
                  {
                    "$ref": "#/components/schemas/Imports"
                  },
                  {
                    "$ref": "#/components/schemas/Records"
                  }
                ]
              },
              "example": {
                "action": "create",
                "idempotency_key": "inventory-2026-12-v1",
                "source": {
                  "kind": "inline",
                  "format": "csv",
                  "filename": "inventory.csv",
                  "content_base64": "U0tVLFF0eQowMDEsMgowMDIsMwo="
                },
                "contract": {
                  "version": "inventory-1",
                  "fields": [
                    {
                      "name": "sku",
                      "source": "SKU",
                      "type": "string"
                    },
                    {
                      "name": "quantity",
                      "source": "Qty",
                      "type": "integer"
                    }
                  ],
                  "business_keys": [
                    "sku"
                  ],
                  "controls": [
                    {
                      "field": "quantity",
                      "expected": "5"
                    }
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The selected read, catalog query or delivery completed.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Job"
                    },
                    {
                      "$ref": "#/components/schemas/ArtifactResult"
                    },
                    {
                      "$ref": "#/components/schemas/CatalogPage"
                    },
                    {
                      "$ref": "#/components/schemas/DeliveryResult"
                    }
                  ]
                }
              }
            }
          },
          "202": {
            "description": "Create accepted. An identical replay can return an already completed result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, query, or source encoding.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "A valid credential is required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access to the selected scope was denied.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The scoped job or artifact could not be found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The selected version, idempotency key, or artifact conflicts with stored state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "The request, source, or record exceeds its size limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "The caller reached the operation rate limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The operation or its configured infrastructure is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "SourceFormat": {
        "type": "string",
        "enum": [
          "csv",
          "tsv",
          "json",
          "jsonl",
          "xlsx",
          "pdf"
        ]
      },
      "Field": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,62}$"
          },
          "type": {
            "type": "string",
            "enum": [
              "string",
              "integer",
              "decimal",
              "date",
              "boolean"
            ]
          },
          "source": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "constant": {
            "type": "string",
            "maxLength": 2000
          },
          "nullable": {
            "type": "boolean"
          },
          "trim": {
            "type": "boolean"
          },
          "decimal_separator": {
            "type": "string",
            "enum": [
              ".",
              ","
            ]
          },
          "thousands_separator": {
            "type": "string",
            "enum": [
              "",
              ",",
              ".",
              " "
            ]
          }
        },
        "required": [
          "name",
          "type"
        ],
        "additionalProperties": false,
        "oneOf": [
          {
            "required": [
              "source"
            ]
          },
          {
            "required": [
              "constant"
            ]
          }
        ],
        "description": "Select exactly one source heading or literal constant. Field names and mapped source headings are unique. Decimal and thousands separators must differ.",
        "allOf": [
          {
            "if": {
              "properties": {
                "thousands_separator": {
                  "const": "."
                }
              },
              "required": [
                "thousands_separator"
              ]
            },
            "then": {
              "properties": {
                "decimal_separator": {
                  "const": ","
                }
              },
              "required": [
                "decimal_separator"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "thousands_separator": {
                  "const": ","
                }
              },
              "required": [
                "thousands_separator"
              ]
            },
            "then": {
              "properties": {
                "decimal_separator": {
                  "const": "."
                }
              }
            }
          }
        ]
      },
      "TotalCheck": {
        "type": "object",
        "properties": {
          "field": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,62}$"
          },
          "expected": {
            "type": "string",
            "pattern": "^[+-]?\\d+(?:\\.\\d+)?$",
            "maxLength": 100
          },
          "where": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 2000
            },
            "propertyNames": {
              "pattern": "^[a-z][a-z0-9_]{0,62}$"
            }
          },
          "tolerance": {
            "type": "string",
            "pattern": "^\\+?\\d+(?:\\.\\d+)?$",
            "maxLength": 100
          }
        },
        "required": [
          "field",
          "expected"
        ],
        "additionalProperties": false,
        "description": "Sum a numeric field on all rows that match the optional string filters. Tolerance is nonnegative and defaults to zero."
      },
      "CellCheck": {
        "type": "object",
        "properties": {
          "cell": {
            "type": "string",
            "description": "A literal workbook cell address within the first 100 columns (A through CV) and rows 1 through 1048576.",
            "pattern": "^(?:[A-Z]|[AB][A-Z]|C[A-V])(?:[1-9][0-9]{0,5}|10(?:[0-3][0-9]{4}|4(?:[0-7][0-9]{3}|8(?:[0-4][0-9]{2}|5(?:[0-6][0-9]|7[0-6])))))$"
          },
          "field": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,62}$"
          },
          "where": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 2000
            },
            "propertyNames": {
              "pattern": "^[a-z][a-z0-9_]{0,62}$"
            }
          },
          "tolerance": {
            "type": "string",
            "pattern": "^\\+?\\d+(?:\\.\\d+)?$",
            "maxLength": 100
          }
        },
        "required": [
          "cell",
          "field"
        ],
        "additionalProperties": false,
        "description": "Compare the independent total in this cell with the sum of the mapped numeric field. A failed check holds the output."
      },
      "WorkbookSheet": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "role": {
                "const": "data"
              },
              "header_row": {
                "type": "integer",
                "minimum": 1,
                "maximum": 1000
              },
              "columns": {
                "type": "object",
                "additionalProperties": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                },
                "maxProperties": 100,
                "propertyNames": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                }
              }
            },
            "required": [
              "name",
              "role"
            ],
            "additionalProperties": false,
            "description": "Map physical headings on this sheet to the common input headings used by the fields."
          },
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "role": {
                "const": "control"
              },
              "checks": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/CellCheck"
                },
                "minItems": 1,
                "maxItems": 100
              }
            },
            "required": [
              "name",
              "role",
              "checks"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "role": {
                "const": "ignore"
              },
              "reason": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              }
            },
            "required": [
              "name",
              "role",
              "reason"
            ],
            "additionalProperties": false
          }
        ]
      },
      "Contract": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Field"
            },
            "minItems": 1,
            "maxItems": 100
          },
          "business_keys": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,62}$"
            },
            "maxItems": 20
          },
          "ignored_columns": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "maxItems": 100
          },
          "controls": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TotalCheck"
            },
            "maxItems": 100
          },
          "aggregate": {
            "type": "object",
            "properties": {
              "group_by": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,62}$"
                },
                "maxItems": 20
              },
              "sums": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,62}$"
                },
                "minItems": 1,
                "maxItems": 20
              }
            },
            "required": [
              "group_by",
              "sums"
            ],
            "additionalProperties": false
          },
          "header_row": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000
          },
          "sheet": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "workbook": {
            "type": "object",
            "properties": {
              "sheets": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/WorkbookSheet"
                },
                "minItems": 1,
                "maxItems": 100,
                "description": "The engine checks unique sheet names and enforces a combined maximum of 100 inline and cell-based checks across the contract.",
                "contains": {
                  "type": "object",
                  "properties": {
                    "role": {
                      "const": "data"
                    }
                  },
                  "required": [
                    "role"
                  ]
                }
              }
            },
            "required": [
              "sheets"
            ],
            "additionalProperties": false,
            "description": "Workbook package mode for XLSX. Assign each actual sheet an explicit role, with at least one data sheet. Use either this option or sheet."
          },
          "records_path": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "maxItems": 10
          },
          "delimiter": {
            "type": "string",
            "enum": [
              ",",
              ";",
              "\t",
              "|"
            ]
          },
          "text_table": {
            "type": "object",
            "properties": {
              "review_ref": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "separator": {
                "type": "string",
                "minLength": 1,
                "maxLength": 10
              }
            },
            "required": [
              "review_ref",
              "separator"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "version",
          "fields"
        ],
        "additionalProperties": false,
        "description": "Versioned mapping contract. Keys, filters, and sums reference declared output fields. Preserve IDs as strings and exact amounts as decimal strings.",
        "allOf": [
          {
            "if": {
              "required": [
                "workbook"
              ]
            },
            "then": {
              "properties": {
                "header_row": {
                  "const": 1
                },
                "records_path": {
                  "maxItems": 0
                },
                "delimiter": {
                  "const": ","
                }
              },
              "not": {
                "anyOf": [
                  {
                    "required": [
                      "sheet"
                    ]
                  },
                  {
                    "required": [
                      "text_table"
                    ]
                  }
                ]
              }
            }
          }
        ]
      },
      "Source": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "kind": {
                "const": "inline"
              },
              "filename": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "format": {
                "$ref": "#/components/schemas/SourceFormat"
              },
              "content_base64": {
                "type": "string",
                "contentEncoding": "base64",
                "minLength": 4,
                "maxLength": 2796204
              }
            },
            "required": [
              "kind",
              "filename",
              "format",
              "content_base64"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "const": "connector"
              },
              "connector_id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[A-Za-z0-9._:-]+$"
              }
            },
            "required": [
              "kind",
              "connector_id"
            ],
            "additionalProperties": false
          }
        ]
      },
      "Create": {
        "type": "object",
        "properties": {
          "action": {
            "const": "create"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "dataset_id": {
            "type": "string",
            "format": "uuid"
          },
          "idempotency_key": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^[A-Za-z0-9._:-]+$"
          },
          "source": {
            "$ref": "#/components/schemas/Source"
          },
          "contract": {
            "$ref": "#/components/schemas/Contract"
          }
        },
        "required": [
          "action",
          "idempotency_key",
          "source",
          "contract"
        ],
        "additionalProperties": false,
        "dependentRequired": {
          "dataset_id": [
            "organization_id"
          ]
        },
        "description": "Describes an admitted job. The worker checks source compatibility after submission. Workbook mode requires an XLSX source and the PDF reader requires text_table. An incompatible source can receive a job ID and then a rejected result."
      },
      "Read": {
        "type": "object",
        "properties": {
          "action": {
            "const": "read"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        },
        "required": [
          "action",
          "job_id"
        ],
        "additionalProperties": false
      },
      "Artifact": {
        "type": "object",
        "properties": {
          "action": {
            "const": "artifact"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "stage": {
            "type": "string",
            "enum": [
              "bronze",
              "silver",
              "gold"
            ]
          }
        },
        "required": [
          "action",
          "job_id",
          "stage"
        ],
        "additionalProperties": false
      },
      "Deliver": {
        "type": "object",
        "properties": {
          "action": {
            "const": "deliver"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "destination_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^[A-Za-z0-9._:-]+$"
          },
          "gold_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        },
        "required": [
          "action",
          "job_id",
          "destination_id",
          "gold_sha256"
        ],
        "additionalProperties": false
      },
      "Datasets": {
        "type": "object",
        "properties": {
          "action": {
            "const": "datasets"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 50
          },
          "after": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "action",
          "organization_id"
        ],
        "additionalProperties": false
      },
      "Imports": {
        "type": "object",
        "properties": {
          "action": {
            "const": "imports"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "dataset_id": {
            "type": "string",
            "format": "uuid"
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 50
          },
          "after": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        },
        "required": [
          "action",
          "organization_id",
          "dataset_id"
        ],
        "additionalProperties": false
      },
      "Records": {
        "type": "object",
        "properties": {
          "action": {
            "const": "records"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "dataset_id": {
            "type": "string",
            "format": "uuid"
          },
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "after_row": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000
          }
        },
        "required": [
          "action",
          "organization_id",
          "dataset_id",
          "job_id"
        ],
        "additionalProperties": false
      },
      "Job": {
        "type": "object",
        "required": [
          "job_id",
          "status"
        ],
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "dataset_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "held",
              "ready",
              "rejected"
            ]
          },
          "engine_version": {
            "type": "string"
          },
          "source_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "contract_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$",
            "description": "SHA-256 of the validated, canonical contract including defaults. Version 2 workbook completion receipts include this field."
          },
          "silver_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "gold_sha256": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-f0-9]{64}$"
          },
          "issue_count": {
            "type": "integer"
          },
          "issues_truncated": {
            "type": "integer"
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "code"
              ],
              "properties": {
                "code": {
                  "type": "string"
                },
                "row": {
                  "type": "integer"
                },
                "field": {
                  "type": "string"
                },
                "source_sheet": {
                  "type": "string"
                }
              }
            }
          },
          "controls": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "expected",
                "actual",
                "passed"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "expected": {
                  "type": "string"
                },
                "actual": {
                  "type": "string"
                },
                "passed": {
                  "type": "boolean"
                },
                "source_sheet": {
                  "type": "string"
                },
                "source_cell": {
                  "type": "string"
                }
              }
            }
          },
          "rows_read": {
            "type": "integer"
          },
          "rows_output": {
            "type": "integer"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "engine_version": {
                  "const": "2"
                },
                "status": {
                  "enum": [
                    "ready",
                    "held",
                    "rejected"
                  ]
                }
              },
              "required": [
                "engine_version",
                "status"
              ]
            },
            "then": {
              "required": [
                "contract_sha256"
              ]
            }
          }
        ]
      },
      "ArtifactResult": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "stage": {
            "type": "string",
            "enum": [
              "bronze",
              "silver",
              "gold"
            ]
          },
          "artifact": {
            "type": "object",
            "description": "Bronze contains filename, format, source_sha256, and content_base64. Silver contains source-grain records. Gold contains the ready records and field types."
          }
        },
        "required": [
          "job_id",
          "stage",
          "artifact"
        ],
        "additionalProperties": false
      },
      "DeliveryResult": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "delivery_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "receipt": {
            "type": "object",
            "properties": {
              "committed": {
                "const": true
              },
              "rows": {
                "type": "integer"
              }
            },
            "required": [
              "committed",
              "rows"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "job_id",
          "delivery_id",
          "receipt"
        ],
        "additionalProperties": false
      },
      "CatalogPage": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "datasets",
              "next_after"
            ],
            "properties": {
              "datasets": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "next_after": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          {
            "type": "object",
            "required": [
              "imports",
              "next_after"
            ],
            "properties": {
              "imports": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "next_after": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          {
            "type": "object",
            "required": [
              "records",
              "next_after"
            ],
            "properties": {
              "records": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "next_after": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          }
        ]
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "JobQuery": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "stage": {
            "type": "string",
            "enum": [
              "bronze",
              "silver",
              "gold"
            ]
          }
        },
        "required": [
          "job_id"
        ],
        "additionalProperties": false
      }
    }
  }
}