{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://platform.latere.ai/docs/apps/latere-app.schema.json",
  "title": "latere-app.yaml",
  "description": "How Latere Apps builds and serves an app. Every key is optional.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "name": {"type": "string", "pattern": "^[a-z0-9]([a-z0-9-]{0,38}[a-z0-9])?$", "description": "The app's slug."},
    "kind": {"enum": ["static", "service"], "description": "Omit to detect."},
    "static": {"$ref": "#/$defs/static"},
    "service": {"$ref": "#/$defs/service"},
    "components": {
      "type": "object",
      "propertyNames": {"pattern": "^[a-z][a-z0-9-]{0,19}$"},
      "additionalProperties": {"$ref": "#/$defs/component"}
    },
    "links": {"type": "array", "maxItems": 10, "items": {"type": "string"}},
    "build": {"type": "object", "additionalProperties": false, "properties": {"env": {"$ref": "#/$defs/env"}}},
    "env": {"$ref": "#/$defs/env"},
    "resources": {
      "type": "object",
      "propertyNames": {"pattern": "^[a-z][a-z0-9-]{0,19}$"},
      "additionalProperties": {"$ref": "#/$defs/resource"}
    }
  },
  "dependentSchemas": {
    "components": {"not": {"anyOf": [{"required": ["kind"]}, {"required": ["static"]}, {"required": ["service"]}]}}
  },
  "$defs": {
    "env": {"type": "object", "additionalProperties": {"type": ["string", "number", "boolean"]}},
    "static": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "build": {"type": "string"},
        "dir": {"type": "string"},
        "spa": {"type": "boolean"},
        "sitemap": {"type": "boolean"},
        "headers": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "object",
            "required": ["path"],
            "properties": {"path": {"type": "string", "pattern": "^/"}},
            "additionalProperties": {"type": "string"}
          }
        }
      }
    },
    "service": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "builder": {"enum": ["jammy-base", "jammy-full"]},
        "start": {"type": "string"},
        "port": {"type": "integer", "minimum": 1, "maximum": 65535},
        "health": {"type": "string", "pattern": "^/"},
        "resources": {
          "type": "object",
          "additionalProperties": false,
          "properties": {"memory": {"type": "string"}, "cpu": {"type": "string"}}
        },
        "replicas": {
          "type": "object",
          "additionalProperties": false,
          "properties": {"min": {"type": "integer", "minimum": 0}, "max": {"type": "integer", "minimum": 0}}
        },
        "public_paths": {"type": "array", "maxItems": 10, "items": {"type": "string", "pattern": "^/"}},
        "forward_authorization": {"type": "boolean"},
        "dockerfile": {
          "type": "object",
          "additionalProperties": false,
          "properties": {"path": {"type": "string"}, "target": {"type": "string"}}
        },
        "migrate": {"type": "string", "maxLength": 1000}
      }
    },
    "component": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "kind": {"enum": ["static", "service", "worker", "cron"]},
        "path": {"type": "string"},
        "route": {"type": "string", "pattern": "^/"},
        "strip_prefix": {"type": "boolean"},
        "static": {"$ref": "#/$defs/static"},
        "service": {"$ref": "#/$defs/service"},
        "env": {"$ref": "#/$defs/env"},
        "schedule": {"type": "string"},
        "start": {"type": "string"}
      }
    },
    "resource": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type"],
      "properties": {
        "type": {"enum": ["postgres", "cache"]},
        "size": {"type": "string"},
        "preview": {"enum": ["copy", "empty"]}
      }
    }
  }
}
