{
  "openapi": "3.1.0",
  "info": {
    "title": "Kungjort external read API (pilot)",
    "version": "1.0.0-pilot",
    "description": "Explicitly enabled read API pilot. Customer policy controls municipalities, expiry, pause, archive-file access and a shared requests-per-minute limit across all customer keys. Keys can expire or be revoked individually. See docs/pilot-api.md for export/replay and identity guarantees. A source reference is not proof of a new decision. No region-wide completeness guarantee. Responses include X-Request-ID for support. Identified customer requests are logged for 30 days by default; credentials and request/response bodies are excluded."
  },
  "servers": [
    {
      "url": "https://handlingar.kungjort.se/api/v1"
    }
  ],
  "security": [
    {
      "pilotKey": []
    }
  ],
  "paths": {
    "/documents": {
      "get": {
        "operationId": "listDocuments",
        "summary": "Search or bootstrap an export",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": ""
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Opaque continuation; preserve all filters."
          },
          {
            "name": "kommun",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "organ",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "doc_type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "dnr",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Meeting date, not modification time."
          },
          {
            "name": "until",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Meeting date, not modification time."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Documents"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "400": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "401": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "403": {
            "description": "Customer access is paused/expired, municipality is outside scope, or archive-file permission is disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "404": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "409": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "429": {
            "description": "Customer-wide rate limit exceeded across all keys. Retry-After is in seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "503": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        }
      }
    },
    "/documents/{id}": {
      "get": {
        "operationId": "getDocument",
        "summary": "Read complete extracted text and sections",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,18}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Document"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "400": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "401": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "403": {
            "description": "Customer access is paused/expired, municipality is outside scope, or archive-file permission is disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "404": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "409": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "429": {
            "description": "Customer-wide rate limit exceeded across all keys. Retry-After is in seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "503": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        }
      }
    },
    "/documents/{id}/files": {
      "get": {
        "operationId": "getOriginalVersions",
        "summary": "List archived byte versions",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,18}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Files"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "400": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "401": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "403": {
            "description": "Customer access is paused/expired, municipality is outside scope, or archive-file permission is disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "404": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "409": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "429": {
            "description": "Customer-wide rate limit exceeded across all keys. Retry-After is in seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "503": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        }
      }
    },
    "/changes": {
      "get": {
        "operationId": "getChanges",
        "summary": "Replay document upserts and tombstones",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": ""
          },
          {
            "name": "cursor",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Start with changes_cursor from the initial documents export."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Changes"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "400": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "401": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "403": {
            "description": "Customer access is paused/expired, municipality is outside scope, or archive-file permission is disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "404": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "409": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "429": {
            "description": "Customer-wide rate limit exceeded across all keys. Retry-After is in seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "503": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        }
      }
    },
    "/cases": {
      "get": {
        "operationId": "getCaseReferences",
        "summary": "Find references across meetings",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": ""
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Opaque continuation; preserve all filters."
          },
          {
            "name": "kommun",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "organ",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "doc_type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "dnr",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Meeting date, not modification time."
          },
          {
            "name": "until",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Meeting date, not modification time."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cases"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "400": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "401": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "403": {
            "description": "Customer access is paused/expired, municipality is outside scope, or archive-file permission is disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "404": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "409": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "429": {
            "description": "Customer-wide rate limit exceeded across all keys. Retry-After is in seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "503": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        }
      }
    },
    "/coverage": {
      "get": {
        "operationId": "getCoverage",
        "summary": "Observed coverage, not a completeness guarantee",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Coverage"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "400": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "401": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "403": {
            "description": "Customer access is paused/expired, municipality is outside scope, or archive-file permission is disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "404": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "409": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "429": {
            "description": "Customer-wide rate limit exceeded across all keys. Retry-After is in seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "503": {
            "description": "Request failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        }
      }
    },
    "/documents/{id}/original": {
      "get": {
        "operationId": "getOriginal",
        "summary": "Read latest or hash-selected archived original",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,18}$"
            }
          },
          {
            "name": "sha256",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Archived bytes; X-Content-SHA256 and ETag identify the file.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "default": {
            "description": "Failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "X-Request-ID": {
                "description": "Server-generated request identifier for support.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "pilotKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "kjp_…"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "DocumentSummary": {
        "type": "object",
        "required": [
          "id",
          "kommun",
          "revision",
          "source_url",
          "parse_status",
          "document_url",
          "original_url"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-9]+$"
          },
          "kommun": {
            "type": "string"
          },
          "kommun_namn": {
            "type": [
              "string",
              "null"
            ]
          },
          "organ": {
            "type": [
              "string",
              "null"
            ]
          },
          "doc_type": {
            "type": "string"
          },
          "doc_type_conf": {
            "type": [
              "string",
              "null"
            ]
          },
          "meeting_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "source_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_sha256": {
            "type": [
              "string",
              "null"
            ]
          },
          "revision": {
            "type": "string",
            "pattern": "^[0-9]+$"
          },
          "parse_status": {
            "type": "string"
          },
          "parse_flags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "parse_version": {
            "type": "integer"
          },
          "parsed_at": {
            "type": "string",
            "format": "date-time"
          },
          "material_md5": {
            "type": [
              "string",
              "null"
            ]
          },
          "pages": {
            "type": [
              "integer",
              "null"
            ]
          },
          "scanned": {
            "type": "boolean"
          },
          "document_url": {
            "type": "string"
          },
          "original_url": {
            "type": "string"
          },
          "publication_organ": {
            "type": [
              "string",
              "null"
            ],
            "description": "Organ in the municipal publication/archive context; the parsed document author remains in organ."
          },
          "publication_meeting_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Meeting date from the municipal publication, if known."
          }
        }
      },
      "CaseReference": {
        "type": "object",
        "required": [
          "case_id",
          "dnr",
          "normalized_dnr",
          "relation"
        ],
        "properties": {
          "case_id": {
            "type": "string"
          },
          "dnr": {
            "type": "string"
          },
          "normalized_dnr": {
            "type": "string"
          },
          "relation": {
            "const": "extracted_reference"
          }
        }
      },
      "Section": {
        "type": "object",
        "required": [
          "section_id",
          "decision_id",
          "paragraf",
          "dnr",
          "block_text",
          "cases"
        ],
        "properties": {
          "section_id": {
            "type": "string"
          },
          "decision_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "ordning": {
            "type": "integer"
          },
          "paragraf": {
            "type": [
              "string",
              "null"
            ]
          },
          "rubrik": {
            "type": [
              "string",
              "null"
            ]
          },
          "dnr": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "diarieplan_kod": {
            "type": [
              "string",
              "null"
            ]
          },
          "beslut_typ": {
            "type": [
              "string",
              "null"
            ]
          },
          "beslut_text": {
            "type": [
              "string",
              "null"
            ]
          },
          "sammanfattning": {
            "type": [
              "string",
              "null"
            ]
          },
          "forslag": {
            "type": [
              "string",
              "null"
            ]
          },
          "yrkanden": {
            "type": [
              "string",
              "null"
            ]
          },
          "beslutsgang": {
            "type": [
              "string",
              "null"
            ]
          },
          "fastighet": {
            "type": [
              "string",
              "null"
            ]
          },
          "beslutsunderlag": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "expedieras_till": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "reservation": {
            "type": "boolean"
          },
          "jav": {
            "type": "boolean"
          },
          "votering": {
            "type": "boolean"
          },
          "block_text": {
            "type": [
              "string",
              "null"
            ]
          },
          "cases": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CaseReference"
            }
          }
        }
      },
      "Document": {
        "allOf": [
          {
            "$ref": "#/components/schemas/DocumentSummary"
          },
          {
            "type": "object",
            "required": [
              "raw_text",
              "raw_md",
              "sections",
              "parsed_original_url"
            ],
            "properties": {
              "raw_text": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "raw_md": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "parsed_original_url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "sections": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Section"
                }
              }
            }
          }
        ]
      },
      "Documents": {
        "type": "object",
        "required": [
          "documents",
          "next_cursor",
          "changes_cursor",
          "consistency"
        ],
        "properties": {
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentSummary"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "changes_cursor": {
            "type": "string"
          },
          "consistency": {
            "const": "upsert_export_then_replay_changes"
          }
        }
      },
      "Cases": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Documents"
          },
          {
            "type": "object",
            "required": [
              "case_id",
              "normalized_dnr",
              "relation"
            ],
            "properties": {
              "case_id": {
                "type": "string"
              },
              "normalized_dnr": {
                "type": "string"
              },
              "relation": {
                "const": "extracted_reference"
              }
            }
          }
        ]
      },
      "Change": {
        "type": "object",
        "required": [
          "revision",
          "document_id",
          "kommun",
          "operation",
          "changed_at"
        ],
        "properties": {
          "revision": {
            "type": "string"
          },
          "document_id": {
            "type": "string"
          },
          "kommun": {
            "type": "string"
          },
          "operation": {
            "enum": [
              "upsert",
              "delete"
            ]
          },
          "changed_at": {
            "type": "string",
            "format": "date-time"
          },
          "document_url": {
            "type": "string"
          },
          "original_url": {
            "type": "string"
          }
        }
      },
      "Changes": {
        "type": "object",
        "required": [
          "changes",
          "has_more",
          "next_cursor"
        ],
        "properties": {
          "changes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Change"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": "string"
          }
        }
      },
      "Files": {
        "type": "object",
        "required": [
          "document_id",
          "files"
        ],
        "properties": {
          "document_id": {
            "type": "string"
          },
          "files": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "sha256",
                "bytes_size",
                "original_url",
                "fetched_at"
              ],
              "properties": {
                "sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "bytes_size": {
                  "type": "string"
                },
                "content_type": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "fetched_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "original_url": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Coverage": {
        "type": "object",
        "required": [
          "generated_at",
          "complete_coverage",
          "coverage"
        ],
        "properties": {
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "complete_coverage": {
            "const": false
          },
          "coverage": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "kommun",
                "organ",
                "doc_type",
                "documents",
                "errors"
              ],
              "properties": {
                "kommun": {
                  "type": "string"
                },
                "organ": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "doc_type": {
                  "type": "string"
                },
                "documents": {
                  "type": "integer"
                },
                "errors": {
                  "type": "integer"
                },
                "first_meeting_date": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "last_meeting_date": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "last_parsed_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "year": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "description": "Publication meeting year, falling back to parsed meeting year."
                },
                "with_publication_context": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    }
  }
}
