{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://peekml.io/peekml.schema.json",
  "title": "peekml.yaml",
  "description": "Describes a model's title, inputs and outputs so PeekML can build its prediction page. Same style as an OpenAPI schema; PeekML additions start with x-.",
  "type": "object",
  "required": ["info", "inputs"],
  "additionalProperties": false,
  "properties": {
    "info": {
      "type": "object",
      "required": ["title"],
      "additionalProperties": false,
      "properties": {
        "title": { "type": "string", "minLength": 1, "description": "Shown as the page heading and used for the model's web address." },
        "description": { "type": "string", "description": "Shown under the title." }
      }
    },
    "inputs": {
      "type": "object",
      "required": ["properties"],
      "properties": {
        "type": { "const": "object" },
        "properties": {
          "type": "object",
          "description": "One entry per model input. The names must match the model's input names exactly.",
          "additionalProperties": { "$ref": "#/$defs/input" }
        }
      }
    },
    "outputs": {
      "type": "object",
      "description": "The outputs to show on the page. Leave out to show every output as raw values.",
      "properties": {
        "type": { "const": "object" },
        "properties": {
          "type": "object",
          "description": "One entry per model output to show. The names must match the model's output names exactly.",
          "additionalProperties": { "$ref": "#/$defs/output" }
        }
      }
    },
    "examples": {
      "type": "array",
      "maxItems": 5,
      "description": "Ready-made inputs, shown as \"Try an example\" buttons. For a model with several inputs, each example is a list of their values in the order the inputs are listed: [42, \"masters\", 0.7] (quotes around text are optional). For a model with one input, each example is just its value; for a picture input that's a public link to the picture, e.g. a GitHub link to a .png or .jpg file (PNG, JPEG, GIF or WebP, up to 2 MB).",
      "items": {
        "type": ["array", "string", "number"],
        "items": { "type": ["number", "string"] }
      }
    }
  },
  "$defs": {
    "input": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": { "enum": ["number", "integer", "string", "array"], "description": "number/integer -> number box (or slider); string -> dropdown (with enum), text box, or picture upload (image inputs); array -> one number box per column (for an input that holds all the features, like X with shape [rows, 4]; name the columns in x-columns)." },
        "x-columns": {
          "description": "For type: array. The name of each column, in the model's order: a list of names, or names with the same settings as a number input.",
          "oneOf": [
            { "type": "array", "minItems": 2, "items": { "type": "string" } },
            { "type": "object", "minProperties": 2, "additionalProperties": { "$ref": "#/$defs/column" } }
          ]
        },
        "description": { "type": "string", "description": "Help text shown under the field." },
        "minimum": { "type": "number" },
        "maximum": { "type": "number" },
        "multipleOf": { "type": "number", "exclusiveMinimum": 0, "description": "Step size for number boxes and sliders." },
        "enum": { "type": "array", "minItems": 1, "items": { "type": "string" }, "description": "Dropdown options for a string input. Quote values like \"yes\" and \"no\"." },
        "x-widget": { "enum": ["slider"], "description": "Show a number input as a slider. Needs minimum, maximum and multipleOf (the step)." },
        "contentMediaType": { "type": "string", "pattern": "^image/", "description": "Optional: marks a picture input (image/*). PeekML also spots these from the model: uint8 RGB pixels with shape [1, height, width, 3], any size." }
      },
      "if": { "properties": { "x-widget": { "const": "slider" } }, "required": ["x-widget"] },
      "then": { "required": ["minimum", "maximum", "multipleOf"] }
    },
    "column": {
      "type": ["object", "null"],
      "properties": {
        "type": { "enum": ["number", "integer"] },
        "description": { "type": "string", "description": "Help text shown under the field." },
        "minimum": { "type": "number" },
        "maximum": { "type": "number" },
        "multipleOf": { "type": "number", "exclusiveMinimum": 0, "description": "Step size." },
        "x-widget": { "enum": ["slider"], "description": "Show as a slider. Needs minimum, maximum and multipleOf." }
      }
    },
    "output": {
      "type": ["object", "null"],
      "properties": {
        "type": { "enum": ["string", "number", "integer", "array"], "description": "string/number/integer -> one value in large text; array -> needs x-classes; no type -> raw values." },
        "description": { "type": "string", "description": "Shown next to the output's name." },
        "enum": { "type": "array", "items": { "type": "string" }, "description": "Optional: the values this output can return (checked during the upload's test run)." },
        "items": { "type": "object" },
        "x-classes": { "type": "array", "minItems": 1, "items": { "type": "string" }, "description": "Class name of each probability column, in the model's order." }
      },
      "if": { "properties": { "type": { "const": "array" } }, "required": ["type"] },
      "then": { "required": ["x-classes"] }
    }
  }
}
