{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/akahu/main/json-schema/akahu-datafile-schema.json",
  "title": "Datafile",
  "description": "**Datafiles** are a structured way to bring financial data into an Application for analysis.\n\nA datafile represents a single file containing a financial information, that follows a supported schema.\n\nWhen a datafile is uploaded to an Application, Akahu Apply will process the information from the file and convert it to a standardised format.\n\nDatafiles can be added to an application only via this API.\n\nNote: Datafiles and their associated data expire 1 year after creation.",
  "x-generated": "2026-10-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/akahu-apply-api-openapi.yml#/components/schemas/Datafile",
  "type": "object",
  "properties": {
    "_id": {
      "$ref": "#/$defs/DatafileId"
    },
    "_application": {
      "type": "string",
      "pattern": "^application_[a-z0-9]{24,27}$",
      "description": "The application that this datafile belongs to."
    },
    "name": {
      "type": "string",
      "maxLength": 255,
      "description": "The filename of this datafile."
    },
    "content_type": {
      "type": "string",
      "enum": [
        "application/json"
      ],
      "description": "The content type of the datafile."
    },
    "schema": {
      "type": "string",
      "description": "The name of the schema for this datafile."
    },
    "status": {
      "$ref": "#/$defs/DatafileStatus"
    },
    "failure_reason": {
      "type": "object",
      "properties": {
        "code": {
          "$ref": "#/$defs/DatafileFailureReasonCode"
        },
        "message": {
          "type": "string",
          "default": "Sorry, something went wrong while processing this datafile. Please try again later."
        }
      },
      "required": [
        "code"
      ],
      "description": "If this datafile has failed to be processed, this field provides additional detail about what went wrong."
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "description": "The date that this datafile was created."
    },
    "updated_at": {
      "type": "string",
      "format": "date-time",
      "description": "The date that this datafile was last updated at."
    },
    "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "Expiry for the datafile, after which the record will be deleted. Expiry varies as the datafile progresses through its lifecycle:\n\n - While the datafile has a status of `pending`, expiry is short lived, ensuring that the record is cleaned up quickly if a file is never uploaded.\n\n - After the datafile upload has been received, a 1 year expiry is set, after which the datafile and all associated data will be permanently deleted."
    }
  },
  "required": [
    "_id",
    "_application",
    "name",
    "content_type",
    "schema",
    "status",
    "created_at",
    "updated_at"
  ],
  "$defs": {
    "DatafileFailureReasonCode": {
      "type": "string",
      "enum": [
        "internal_error",
        "invalid_input",
        "timeout",
        "malware_scan_failed",
        "malware_detected"
      ]
    },
    "DatafileId": {
      "type": "string",
      "pattern": "^dat_[a-z0-9]{24,27}$"
    },
    "DatafileStatus": {
      "type": "string",
      "enum": [
        "pending",
        "processing",
        "completed",
        "failed"
      ],
      "description": "The status of a datafile:\n\n - `pending` The datafile record exists, but the file has not yet been fully uploaded.\n\n - `processing` Akahu Apply is extracting and enriching the data from this datafile.\n\n - `completed` This datafile has been successfully processed.\n\n - `failed` This datafile has not been successfully processed. See the `failure_reason` for more detail."
    }
  }
}