{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.hookbase.app/schemas/fixture-v1.json",
  "title": "Hookbase webhook fixture (v1)",
  "description": "One webhook delivery as the app under test receives it. `hookbase fixtures pull` writes these files and `hookbase test run` sends them. A fixture never holds a signature, the delivery and event ids, or the values of the destination's custom and auth headers: `test run` signs each send with a test secret, gives it its own ids, and takes header values from hookbase.tests.yaml. See https://www.hookbase.app/docs/receive/guide/ci-testing",
  "type": "object",
  "required": ["version", "origin", "request"],
  "properties": {
    "$schema": {
      "type": "string",
      "description": "This schema's URL, so editors can validate the file."
    },
    "version": {
      "const": 1,
      "description": "The fixture format version."
    },
    "origin": {
      "type": "object",
      "description": "Where the fixture came from. `test run` sends fixtures in receivedAt order and matches them by eventType; `fixtures pull --update refresh` finds a file's event by destination, eventId and route.",
      "required": ["kind"],
      "properties": {
        "kind": {
          "enum": ["event", "catalog", "manual"],
          "description": "event: a delivery the destination received. catalog: a provider sample payload. manual: written by hand."
        },
        "eventId": {
          "type": ["string", "null"],
          "description": "The Hookbase event id. Catalog fixtures have a deterministic id, the same on every pull. With `ids: stable`, `test run` sends it as X-Event-ID."
        },
        "receivedAt": {
          "type": ["string", "null"],
          "description": "When Hookbase received the event (ISO 8601). `test run` sends fixtures oldest first; null for catalog samples."
        },
        "eventType": {
          "type": ["string", "null"],
          "description": "The event type, matched by `--event-type` and `tests[].match.eventType`."
        },
        "source": {
          "description": "The source the event came in through.",
          "anyOf": [
            { "type": "null" },
            {
              "type": "object",
              "required": ["id", "slug"],
              "properties": {
                "id": { "type": "string" },
                "slug": { "type": "string" },
                "name": { "type": "string" }
              }
            }
          ]
        },
        "route": {
          "description": "The route the delivery went through.",
          "anyOf": [
            { "type": "null" },
            {
              "type": "object",
              "required": ["id"],
              "properties": {
                "id": { "type": "string" },
                "name": { "type": ["string", "null"] }
              }
            }
          ]
        },
        "destination": {
          "description": "The destination the fixture was pulled from.",
          "anyOf": [
            { "type": "null" },
            {
              "type": "object",
              "required": ["id", "slug"],
              "properties": {
                "id": { "type": "string" },
                "slug": { "type": "string" },
                "name": { "type": "string" }
              }
            }
          ]
        },
        "catalog": {
          "description": "Catalog fixtures: the provider and event type of the sample.",
          "anyOf": [
            { "type": "null" },
            {
              "type": "object",
              "required": ["providerId", "eventType"],
              "properties": {
                "providerId": { "type": "string" },
                "eventType": { "type": "string" }
              }
            }
          ]
        },
        "deliveryStatus": {
          "type": ["string", "null"],
          "description": "The delivery's status when it was pulled, such as delivered or failed."
        }
      }
    },
    "request": {
      "type": "object",
      "description": "The request to send.",
      "required": ["method", "path", "bodyEncoding"],
      "properties": {
        "method": {
          "type": "string",
          "pattern": "^[A-Za-z]+$",
          "description": "The HTTP method."
        },
        "path": {
          "type": "string",
          "pattern": "^/",
          "description": "Path and query, appended to the test target. Secret-looking segments of the destination URL are `:redacted`."
        },
        "headers": {
          "type": "object",
          "description": "Headers sent as they are. The names test run sets itself (Host, Content-Length, Transfer-Encoding, Connection, the webhook-* and x-hookbase-* signature headers, X-Hookbase-Hop, X-Delivery-ID and X-Event-ID) are refused, matched case-insensitively. Values can't hold a line break, NUL or a character outside Latin-1.",
          "propertyNames": {
            "pattern": "^[!#$%&'*+.^_`|~0-9A-Za-z-]+$",
            "not": {
              "pattern": "^(?:[Hh][Oo][Ss][Tt]|[Cc][Oo][Nn][Tt][Ee][Nn][Tt]-[Ll][Ee][Nn][Gg][Tt][Hh]|[Tt][Rr][Aa][Nn][Ss][Ff][Ee][Rr]-[Ee][Nn][Cc][Oo][Dd][Ii][Nn][Gg]|[Cc][Oo][Nn][Nn][Ee][Cc][Tt][Ii][Oo][Nn]|[Ww][Ee][Bb][Hh][Oo][Oo][Kk]-[Ii][Dd]|[Ww][Ee][Bb][Hh][Oo][Oo][Kk]-[Tt][Ii][Mm][Ee][Ss][Tt][Aa][Mm][Pp]|[Ww][Ee][Bb][Hh][Oo][Oo][Kk]-[Ss][Ii][Gg][Nn][Aa][Tt][Uu][Rr][Ee]|[Xx]-[Hh][Oo][Oo][Kk][Bb][Aa][Ss][Ee]-[Ii][Dd]|[Xx]-[Hh][Oo][Oo][Kk][Bb][Aa][Ss][Ee]-[Tt][Ii][Mm][Ee][Ss][Tt][Aa][Mm][Pp]|[Xx]-[Hh][Oo][Oo][Kk][Bb][Aa][Ss][Ee]-[Ss][Ii][Gg][Nn][Aa][Tt][Uu][Rr][Ee]|[Xx]-[Hh][Oo][Oo][Kk][Bb][Aa][Ss][Ee]-[Hh][Oo][Pp]|[Xx]-[Dd][Ee][Ll][Ii][Vv][Ee][Rr][Yy]-[Ii][Dd]|[Xx]-[Ee][Vv][Ee][Nn][Tt]-[Ii][Dd])$"
            }
          },
          "additionalProperties": {
            "type": "string",
            "pattern": "^[\\u0001-\\u0009\\u000B\\u000C\\u000E-\\u00FF]*$"
          }
        },
        "omittedHeaders": {
          "type": "array",
          "description": "Headers the destination sends whose values never leave Hookbase. Set the ones your app needs under `headers:` in hookbase.tests.yaml.",
          "items": {
            "type": "object",
            "required": ["name", "from"],
            "properties": {
              "name": { "type": "string" },
              "from": {
                "enum": ["headers", "auth"],
                "description": "headers: one of the destination's custom headers. auth: from its auth config."
              }
            }
          }
        },
        "bodyEncoding": {
          "enum": ["json", "text", "none"],
          "description": "json: `body` is a JSON value, sent serialized. text: `body` is a string, sent as it is. none: no body (`body` is ignored)."
        },
        "body": {
          "description": "The body: a JSON value (json), a string (text) or null (none)."
        }
      },
      "allOf": [
        {
          "if": { "properties": { "bodyEncoding": { "const": "text" } } },
          "then": { "required": ["body"], "properties": { "body": { "type": "string" } } }
        },
        {
          "if": { "properties": { "bodyEncoding": { "const": "json" } } },
          "then": { "required": ["body"] }
        }
      ]
    },
    "scrub": {
      "description": "What Hookbase scrubbed before the fixture left it. For review only: `test run` ignores it.",
      "anyOf": [
        { "type": "null" },
        {
          "type": "object",
          "properties": {
            "version": {
              "type": "integer",
              "description": "The scrubber version. A new version can change existing fakes."
            },
            "fields": {
              "type": "array",
              "description": "One entry per path, kind and rule. Array indices are collapsed to [*].",
              "items": {
                "type": "object",
                "properties": {
                  "path": { "type": "string", "description": "$.a.b, $.items[*].x or $[\"dotted.key\"]; $ is a whole text body, and $..* counts what didn't fit in the report." },
                  "kind": { "type": "string", "description": "secret, email, phone, name, handle, street, city, postal, ip, dob, gov_id or card, or redacted for a redaction policy." },
                  "by": { "type": "string", "description": "policy, forced, builtin, user or output." },
                  "count": { "type": "integer", "description": "Values scrubbed at this path." }
                }
              }
            },
            "kept": {
              "type": "array",
              "items": { "type": "string" },
              "description": "`keep` paths that left a value as it was."
            },
            "warnings": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Things to check before committing, such as free text that wasn't checked for names."
            }
          }
        }
      ]
    }
  }
}
