{
  "title": "CodeChunk",
  "@id": "stencila:CodeChunk",
  "extends": "CodeBlock",
  "role": "secondary",
  "status": "unstable",
  "category": "code",
  "description": "A executable chunk of code.",
  "properties": {
    "type": {
      "@id": "schema:type",
      "description": "The name of the type.",
      "type": "string",
      "enum": [
        "CodeChunk"
      ],
      "default": "CodeChunk",
      "from": "Entity"
    },
    "id": {
      "@id": "schema:id",
      "description": "The identifier for this item.",
      "type": "string",
      "from": "Entity"
    },
    "meta": {
      "@id": "stencila:meta",
      "description": "Metadata associated with this item.",
      "type": "object",
      "from": "Entity"
    },
    "programmingLanguage": {
      "@id": "schema:programmingLanguage",
      "description": "The programming language of the code.",
      "type": "string",
      "from": "Code"
    },
    "format": {
      "@id": "schema:encodingFormat",
      "aliases": [
        "encoding",
        "encodingFormat"
      ],
      "description": "Media type, typically expressed using a MIME format, of the code.",
      "$comment": "This property allows the differentiation of formats using the same programming language\nor variants of a programming language. An example is using `programmingLanguage` \"json\" and\n`encodingFormat` \"application/ld+json\" for JSON-LD code examples.\n",
      "type": "string",
      "from": "Code"
    },
    "text": {
      "@id": "schema:text",
      "description": "The text of the code.",
      "type": "string",
      "from": "Code"
    },
    "exportFrom": {
      "@id": "stencila:exportFrom",
      "aliases": [
        "export"
      ],
      "description": "A compilation directive giving the name of the variable to export\ninto the content of the code block.\n",
      "type": "string",
      "from": "CodeBlock"
    },
    "importTo": {
      "@id": "stencila:importTo",
      "aliases": [
        "export"
      ],
      "description": "A compilation directive giving the name of the variable to import\nthe content of the code block as.\n",
      "type": "string",
      "from": "CodeBlock"
    },
    "imports": {
      "@id": "stencila:imports",
      "description": "Software packages that the code chunk imports",
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "$ref": "SoftwareSourceCode.schema.json"
          },
          {
            "$ref": "SoftwareApplication.schema.json"
          }
        ]
      },
      "from": "CodeChunk",
      "aliases": [
        "import"
      ]
    },
    "declares": {
      "@id": "stencila:declares",
      "description": "Variables that the code chunk declares.",
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "$ref": "Variable.schema.json"
          },
          {
            "$ref": "Function.schema.json"
          }
        ]
      },
      "from": "CodeChunk",
      "aliases": [
        "declare"
      ]
    },
    "assigns": {
      "@id": "stencila:assigns",
      "description": "Variables that the code chunk assigns to.",
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "$ref": "Variable.schema.json"
          }
        ]
      },
      "$comment": "In languages such as Python and R we are unable\nto differentiate between an assignment that\nis a declaration and an assignment that is an alteration\n(a re-assignment).\nThe \"primary\" compiler keeps a track of the variables\ndeclared in code chunks prior to the current chunk in the\ndocument and may treat an assignment as a declaration.\n",
      "from": "CodeChunk",
      "aliases": [
        "assign"
      ]
    },
    "alters": {
      "@id": "stencila:alters",
      "description": "Names of variables that the code chunk alters.",
      "type": "array",
      "items": {
        "type": "string"
      },
      "$comment": "This property allows users to add undetected\nalterations (i.e. not assignments) to this list. Chunks that alter a variable\nneed to be inserted into the dependency graph between `declares` and `uses`\n",
      "from": "CodeChunk",
      "aliases": [
        "alter"
      ]
    },
    "uses": {
      "@id": "stencila:uses",
      "description": "Names of variables that the code chunk uses (but does not alter).",
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "$ref": "Variable.schema.json"
          }
        ]
      },
      "from": "CodeChunk",
      "aliases": [
        "use"
      ]
    },
    "reads": {
      "@id": "stencila:reads",
      "description": "Filesystem paths that this code chunk reads from.",
      "type": "array",
      "items": {
        "type": "string"
      },
      "from": "CodeChunk",
      "aliases": [
        "read"
      ]
    },
    "outputs": {
      "@id": "stencila:outputs",
      "description": "Outputs from executing the chunk.",
      "type": "array",
      "items": {
        "$ref": "Node.schema.json"
      },
      "from": "CodeChunk",
      "aliases": [
        "output"
      ]
    },
    "errors": {
      "@id": "stencila:errors",
      "description": "Errors when compiling or executing the chunk.",
      "type": "array",
      "items": {
        "$ref": "CodeError.schema.json"
      },
      "from": "CodeChunk",
      "aliases": [
        "error"
      ]
    },
    "duration": {
      "@id": "stencila:duration",
      "description": "Duration in seconds of the last execution of the chunk.",
      "type": "number",
      "minimum": 0,
      "from": "CodeChunk"
    }
  },
  "file": "CodeChunk.schema.yaml",
  "children": [],
  "descendants": [],
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schema.stenci.la/v0/CodeChunk.schema.json",
  "source": "https://github.com/stencila/schema/blob/master/CodeChunk.schema.yaml",
  "type": "object",
  "propertyAliases": {
    "encoding": "format",
    "encodingFormat": "format",
    "export": "importTo",
    "import": "imports",
    "declare": "declares",
    "assign": "assigns",
    "alter": "alters",
    "use": "uses",
    "read": "reads",
    "output": "outputs",
    "error": "errors"
  },
  "additionalProperties": false,
  "required": [
    "type",
    "text"
  ]
}
