{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-25 Integration Connectors and SDKs",
    "version": "1.0.0",
    "description": "Base path /api/ohn/v1. Every POST requires Idempotency-Key; mutations use expected_version. Routes default-deny on role AND purpose (connector_management). The connector stores references and counts only: no credentials, URLs or patient data. Validation failures are 422 domain_validation_failed with details = {field: code} (first failing check per field). Dependencies (OHN-45 credentials, OHN-39 endpoint trust, OHN-21 FHIR gateway) fail closed with 503 dependency_unavailable. The synthetic sign-in of the TypeScript reference (POST /connectors/synthetic-token) is not part of this contract: tokens come from the platform gateway."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "paths": {
    "/connectors": {
      "post": {
        "operationId": "installConnector",
        "summary": "Install a partner connector (OHN-25-API-001; F001; W001)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "Installed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectorReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Connector"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listConnectors",
        "summary": "List connectors in the jurisdiction (P001/P002/P003)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "health",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "partner",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Opaque cursor from next_cursor"
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectorList"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/status": {
      "get": {
        "operationId": "connectorStatus",
        "summary": "Fleet status summary and exceptions (P003)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/{id}": {
      "get": {
        "operationId": "getConnector",
        "summary": "Connector detail with history and latest checks",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/{id}/test": {
      "post": {
        "operationId": "testConnector",
        "summary": "Credential/trust check or synthetic dry run (OHN-25-API-002; P005/P006)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TestCommand"
              }
            }
          }
        }
      }
    },
    "/connectors/{id}/health": {
      "get": {
        "operationId": "connectorHealth",
        "summary": "Connector health with evidence (OHN-25-API-003)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/{id}/transitions": {
      "post": {
        "operationId": "transitionConnector",
        "summary": "Advance the install workflow (W001)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectorReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Transition"
              }
            }
          }
        }
      }
    },
    "/connectors/{id}/mappings": {
      "post": {
        "operationId": "configureMapping",
        "summary": "Add a mapping configuration version (F002)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Mapping"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listMappings",
        "summary": "Mapping configuration history",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/{id}/sync-runs": {
      "post": {
        "operationId": "recordSync",
        "summary": "Record a synchronization run (W002)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SyncRun"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listSyncRuns",
        "summary": "Synchronization runs",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/{id}/upgrades": {
      "post": {
        "operationId": "proposeUpgrade",
        "summary": "Propose an upgrade (F003; W003)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Upgrade"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listUpgrades",
        "summary": "Upgrades of a connector",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/{id}/upgrades/{uid}/transitions": {
      "post": {
        "operationId": "advanceUpgrade",
        "summary": "Advance an upgrade (W003)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "uid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpgradeStep"
              }
            }
          }
        }
      }
    },
    "/connectors/sdk-versions": {
      "get": {
        "operationId": "listSdkVersions",
        "summary": "SDK release registry",
        "tags": [
          "OHN-25"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      },
      "post": {
        "operationId": "upsertSdkVersion",
        "summary": "Register or update an SDK release",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SdkRelease"
              }
            }
          }
        }
      }
    },
    "/connectors/policy": {
      "get": {
        "operationId": "readPolicy",
        "summary": "Read policy (unset = fail closed)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      },
      "post": {
        "operationId": "writePolicy",
        "summary": "Write policy",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Policy"
              }
            }
          }
        }
      }
    },
    "/connectors/code-lists/{list}": {
      "get": {
        "operationId": "listCodes",
        "summary": "Read a controlled code list",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "connector_type",
                "environment",
                "retry_policy",
                "sdk_language"
              ]
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      },
      "post": {
        "operationId": "upsertCodes",
        "summary": "Upsert code list entries",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "connector_type",
                "environment",
                "retry_policy",
                "sdk_language"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeListUpsert"
              }
            }
          }
        }
      }
    },
    "/connectors/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Drain outbox (no sink: nothing marked delivered)",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DrainResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        }
      }
    },
    "/connectors/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Report catalogue",
        "tags": [
          "OHN-25"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run OHN-25-R001..R003",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-25-R001",
                "OHN-25-R002",
                "OHN-25-R003"
              ]
            }
          },
          {
            "name": "partner",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "version",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "R001/R002: connector release; R003: SDK version"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            },
            "description": "R001: connector health"
          },
          {
            "name": "resource",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "R002: FHIR resource"
          },
          {
            "name": "country",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            },
            "description": "R003"
          },
          {
            "name": "language",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "R003"
          },
          {
            "name": "period_from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "description": "Narrows the synchronisation runs, not the connectors"
          },
          {
            "name": "period_to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Opaque cursor (page size 100)"
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/connectors/reports/{reportId}/export": {
      "post": {
        "operationId": "exportReport",
        "summary": "Create a signed single-use export",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-25-R001",
                "OHN-25-R002",
                "OHN-25-R003"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExportReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "413": {
            "description": "Request body larger than 256 kB (payload_too_large)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        }
      }
    },
    "/connectors/exports/{token}": {
      "get": {
        "operationId": "downloadExport",
        "summary": "Download an export once",
        "tags": [
          "OHN-25"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{20,64}$"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "The export file (attachment); single use",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          },
          "410": {
            "description": "Export expired (export_expired) or already downloaded (export_consumed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Export failed its integrity check (export_integrity_failed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/health/ohn-25": {
      "get": {
        "operationId": "health",
        "summary": "Liveness and dependency modes",
        "tags": [
          "OHN-25"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "const": "ok"
                    },
                    "module": {
                      "const": "OHN-25"
                    },
                    "dependencies": {
                      "type": "object",
                      "description": "mode of the OHN-45 (ohn45), OHN-39 (ohn39) and OHN-21 (ohn21) gateways: synthetic | unconfigured | live"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Database unreachable",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "const": "unavailable"
                    }
                  }
                }
              }
            }
          }
        },
        "security": []
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Stable machine code, e.g. domain_validation_failed, version_conflict, separation_of_duties, canary_not_proven."
          },
          "message": {
            "type": "string"
          },
          "details": {
            "description": "For validation failures: field name -> zod issue code (invalid_type, too_small, too_big, invalid_string, invalid_enum_value, unrecognized_keys under \"_\"), or a domain code such as not_in_jurisdiction_code_list. For refusals: evidence (current_version, runs, required_runs, ...)."
          },
          "type": {
            "type": "string",
            "description": "RFC 9457 problem type (Java service)."
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "trace_id": {
            "type": "string"
          }
        }
      },
      "Connector": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "partner_org",
          "connector_type",
          "version",
          "environment",
          "credentials_ref",
          "fhir_endpoint"
        ],
        "properties": {
          "partner_org": {
            "type": "string",
            "format": "uuid"
          },
          "connector_type": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "version": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]{1,32})?$"
          },
          "environment": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "credentials_ref": {
            "type": "string",
            "format": "uuid"
          },
          "fhir_endpoint": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "TestCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind"
        ],
        "properties": {
          "kind": {
            "enum": [
              "credentials",
              "dry_run"
            ]
          },
          "sample_resource": {
            "enum": [
              "Patient",
              "Observation",
              "Encounter",
              "Condition",
              "Immunization"
            ]
          }
        }
      },
      "Transition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ],
        "properties": {
          "to_state": {
            "enum": [
              "registered",
              "credentials_checked",
              "conformance_passed",
              "approved",
              "enabled"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "Mapping": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "resource_profile",
          "mapping_version",
          "retry_policy",
          "sync_schedule",
          "expected_version",
          "reason"
        ],
        "properties": {
          "resource_profile": {
            "type": "string",
            "format": "uuid"
          },
          "mapping_version": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]{1,32})?$"
          },
          "retry_policy": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "sync_schedule": {
            "type": "string",
            "minLength": 5,
            "maxLength": 120,
            "pattern": "^[0-9*/,\\- ]+$",
            "description": "Numeric cron-style schedule; surrounding whitespace is trimmed before the length and pattern checks."
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "SyncRun": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "records_polled",
          "records_rejected",
          "lag_seconds"
        ],
        "properties": {
          "records_polled": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000000
          },
          "records_rejected": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000000
          },
          "lag_seconds": {
            "type": "integer",
            "minimum": 0,
            "maximum": 31536000
          },
          "error_code": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "resource": {
            "type": "string",
            "maxLength": 64
          }
        },
        "description": "records_rejected must not exceed records_polled (422 details.records_rejected = exceeds_records_polled)."
      },
      "Upgrade": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "to_version",
          "backward_compatibility_report",
          "rollback_plan"
        ],
        "properties": {
          "to_version": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]{1,32})?$"
          },
          "backward_compatibility_report": {
            "type": "string",
            "format": "uuid"
          },
          "rollback_plan": {
            "type": "string",
            "minLength": 20,
            "maxLength": 8192
          }
        }
      },
      "UpgradeStep": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ],
        "properties": {
          "to_state": {
            "enum": [
              "compatibility_tested",
              "canary",
              "deployed",
              "rolled_back"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "SdkRelease": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sdk",
          "language",
          "version",
          "country",
          "registered_clients",
          "end_of_support"
        ],
        "properties": {
          "sdk": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{1,63}$"
          },
          "language": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "version": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]{1,32})?$"
          },
          "country": {
            "type": "string",
            "pattern": "^[A-Z]{2}$"
          },
          "registered_clients": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100000000
          },
          "end_of_support": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
            "description": "Date (YYYY-MM-DD) after which the release is unsupported; null when no end is announced. The key is required."
          }
        }
      },
      "Policy": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "max_lag_seconds",
          "min_success_bp",
          "canary_min_runs",
          "approval_reference"
        ],
        "properties": {
          "max_lag_seconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 31536000
          },
          "min_success_bp": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 10000
          },
          "canary_min_runs": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 10000
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3,
            "maxLength": 256
          }
        },
        "description": "Thresholds are null until the jurisdiction decides them; while any is null, health is unknown, approval and deployment are refused (policy_not_configured). No default values exist."
      },
      "CodeListUpsert": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "entries"
        ],
        "properties": {
          "entries": {
            "type": "array",
            "minItems": 1,
            "maxItems": 200,
            "items": {
              "$ref": "#/components/schemas/CodeListEntry"
            }
          }
        }
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "format"
        ],
        "properties": {
          "format": {
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "$ref": "#/components/schemas/ReportFilters",
            "default": {}
          }
        }
      },
      "CodeListEntry": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code",
          "label_en",
          "label_fr"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "label_en": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "label_fr": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "active": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "ReportFilters": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "partner": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "string",
            "maxLength": 64
          },
          "status": {
            "type": "string",
            "maxLength": 32
          },
          "resource": {
            "type": "string",
            "maxLength": 64
          },
          "country": {
            "type": "string",
            "pattern": "^[A-Z]{2}$"
          },
          "language": {
            "type": "string",
            "maxLength": 64
          },
          "period_from": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "period_to": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          }
        }
      },
      "Receipt": {
        "type": "object",
        "required": [
          "receipt_id",
          "committed_at",
          "aggregate_id",
          "version",
          "status"
        ],
        "properties": {
          "receipt_id": {
            "type": "string",
            "format": "uuid"
          },
          "committed_at": {
            "type": "string",
            "format": "date-time"
          },
          "aggregate_id": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "enum": [
              "committed",
              "denied"
            ]
          }
        }
      },
      "ConnectorView": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "partner_org": {
            "type": "string",
            "format": "uuid"
          },
          "connector_type": {
            "type": "string"
          },
          "version": {
            "type": "integer",
            "description": "Row version used as expected_version."
          },
          "connector_version": {
            "type": "string",
            "description": "Installed connector release (semver)."
          },
          "environment": {
            "type": "string"
          },
          "credentials_ref": {
            "type": "string",
            "format": "uuid"
          },
          "fhir_endpoint": {
            "type": "string",
            "format": "uuid"
          },
          "state": {
            "enum": [
              "registered",
              "credentials_checked",
              "conformance_passed",
              "approved",
              "enabled"
            ]
          },
          "health": {
            "enum": [
              "unknown",
              "healthy",
              "degraded"
            ]
          },
          "installed_by": {
            "type": "string",
            "format": "uuid"
          },
          "approved_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "last_sync_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "provenance": {
            "type": "object",
            "properties": {
              "source_system_id": {
                "type": "string",
                "format": "uuid"
              },
              "provenance_ref": {
                "type": "string",
                "format": "uuid"
              }
            }
          }
        }
      },
      "ConnectorReceipt": {
        "type": "object",
        "properties": {
          "connector": {
            "$ref": "#/components/schemas/ConnectorView"
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "ConnectorList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ConnectorView"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "description": "Opaque; pass as ?cursor= for the next page (page size 50)."
          }
        }
      },
      "HealthCheck": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "enum": [
              "credentials",
              "trust",
              "dry_run"
            ]
          },
          "passed": {
            "type": "boolean"
          },
          "detail_code": {
            "type": "string"
          },
          "checked_by": {
            "type": "string",
            "format": "uuid"
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TestResult": {
        "type": "object",
        "properties": {
          "connector_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "enum": [
              "credentials",
              "dry_run"
            ]
          },
          "passed": {
            "type": "boolean"
          },
          "checks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/HealthCheck"
            }
          },
          "preview": {
            "type": [
              "object",
              "null"
            ],
            "description": "Dry run only: {synthetic:true, resource_type, payload}. The payload is a fixed SYNTHETIC sample, never real data."
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "ReportResult": {
        "type": "object",
        "properties": {
          "report_id": {
            "enum": [
              "OHN-25-R001",
              "OHN-25-R002",
              "OHN-25-R003"
            ]
          },
          "title": {
            "type": "string"
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "maxItems": 100
          },
          "summary": {
            "type": "object"
          },
          "state": {
            "enum": [
              "rendered",
              "no_authorized_data"
            ]
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ExportReceipt": {
        "type": "object",
        "properties": {
          "export_id": {
            "type": "string",
            "format": "uuid"
          },
          "report_id": {
            "type": "string"
          },
          "format": {
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "rows": {
            "type": "integer"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "single_use": {
            "const": true
          },
          "download_path": {
            "type": "string",
            "description": "/api/ohn/v1/connectors/exports/{token}; valid for 5 minutes, once, for the requesting principal only."
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "DrainResult": {
        "type": "object",
        "properties": {
          "delivered": {
            "const": 0
          },
          "pending": {
            "type": "integer"
          }
        },
        "description": "No sink is configured by this endpoint: nothing is ever marked delivered here. Events are relayed from the platform outbox."
      }
    }
  }
}