{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://freebin.org/schemas/bin-config.v1.json",
  "title": "Freebin portable bin configuration v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "version", "bin", "rules"],
  "properties": {
    "$schema": { "const": "https://freebin.org/schemas/bin-config.v1.json" },
    "version": { "const": 1 },
    "bin": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "response", "forwarding"],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 60 },
        "response": {
          "type": "object",
          "additionalProperties": false,
          "required": ["status", "body", "contentType", "headers"],
          "properties": {
            "status": { "type": "integer", "minimum": 100, "maximum": 599 },
            "body": { "type": "string", "maxLength": 500 },
            "contentType": { "type": "string", "maxLength": 500 },
            "headers": { "type": "object", "maxProperties": 20, "additionalProperties": { "type": "string", "maxLength": 500 } }
          }
        },
        "forwarding": {
          "type": "object",
          "additionalProperties": false,
          "required": ["enabled", "url", "authHeaders"],
          "properties": {
            "enabled": { "type": "boolean" },
            "url": { "type": ["string", "null"], "maxLength": 2000 },
            "authHeaders": { "type": "array", "maxItems": 10, "uniqueItems": true, "items": { "type": "string" } }
          }
        }
      }
    },
    "rules": {
      "type": "array",
      "maxItems": 10,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "enabled", "conditions", "responseStatus", "responseBody", "responseContentType", "responseHeaders", "responseDelayMs"],
        "properties": {
          "name": { "type": "string", "minLength": 1, "maxLength": 80 },
          "enabled": { "type": "boolean" },
          "conditions": {
            "type": "array", "minItems": 1, "maxItems": 5,
            "items": {
              "type": "object", "additionalProperties": false, "required": ["source", "operator"],
              "properties": {
                "source": { "enum": ["method", "path", "query", "header", "body"] },
                "key": { "type": "string" },
                "operator": { "enum": ["equals", "exists", "contains", "glob"] },
                "value": { "type": "string", "maxLength": 500 }
              }
            }
          },
          "responseStatus": { "type": "integer", "minimum": 200, "maximum": 599 },
          "responseBody": { "type": "string", "maxLength": 20480 },
          "responseContentType": { "type": "string", "maxLength": 500 },
          "responseHeaders": { "type": "object", "maxProperties": 20, "additionalProperties": { "type": "string", "maxLength": 500 } },
          "responseDelayMs": { "type": "integer", "minimum": 0, "maximum": 5000 }
        }
      }
    }
  }
}
