{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-42 Sensitive Data Segmentation",
    "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 (sensitive_data_governance). Anything unlabeled, pending or unpolicied is withheld."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "paths": {
    "/classification/decisions": {
      "post": {
        "operationId": "classify",
        "summary": "Classify a resource against published policies (API-001; W001)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Classify"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listDecisions",
        "summary": "Decisions (status, resource_ref)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "resource_ref",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/decisions/{id}": {
      "get": {
        "operationId": "getDecision",
        "summary": "Decision with history",
        "tags": [
          "OHN-42"
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/decisions/{id}/review": {
      "post": {
        "operationId": "reviewDecision",
        "summary": "Clinical review of a held decision (not the classifier)",
        "tags": [
          "OHN-42"
        ],
        "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
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReviewDecision"
              }
            }
          }
        }
      }
    },
    "/classification/labels": {
      "get": {
        "operationId": "listLabels",
        "summary": "Labels in force (status, patient_ref)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "patient_ref",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/labels/{id}": {
      "get": {
        "operationId": "getLabel",
        "summary": "Label inspector for a resource ref",
        "tags": [
          "OHN-42"
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/policies": {
      "get": {
        "operationId": "listPolicies",
        "summary": "Sensitivity policies (API-002)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 16
            }
          },
          {
            "name": "resource_category",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "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": "createPolicy",
        "summary": "Draft a sensitivity policy (F001)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Policy"
              }
            }
          }
        }
      }
    },
    "/classification/policies/{id}": {
      "get": {
        "operationId": "getPolicy",
        "summary": "One policy",
        "tags": [
          "OHN-42"
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/policies/{id}/publish": {
      "post": {
        "operationId": "publishPolicy",
        "summary": "Publish a policy (author cannot publish; API-003)",
        "tags": [
          "OHN-42"
        ],
        "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
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Publish"
              }
            }
          }
        }
      }
    },
    "/classification/evaluations": {
      "post": {
        "operationId": "evaluate",
        "summary": "Evaluate/enforce disclosure for resources (F002; W002)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Evaluation"
              }
            }
          }
        }
      }
    },
    "/classification/exceptions": {
      "post": {
        "operationId": "requestException",
        "summary": "Request a time-bounded exception (F003; W003)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExceptionRequest"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listExceptions",
        "summary": "Exceptions (state, sensitivity_type)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 16
            }
          },
          {
            "name": "sensitivity_type",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/exceptions/{id}": {
      "get": {
        "operationId": "getException",
        "summary": "Exception with reviews and history",
        "tags": [
          "OHN-42"
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/exceptions/{id}/reviews": {
      "post": {
        "operationId": "reviewException",
        "summary": "Review an exception; needs one approval per reviewer role",
        "tags": [
          "OHN-42"
        ],
        "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
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExceptionReview"
              }
            }
          }
        }
      }
    },
    "/classification/exceptions/{id}/revoke": {
      "post": {
        "operationId": "revokeException",
        "summary": "Revoke an approved exception (privacy officer)",
        "tags": [
          "OHN-42"
        ],
        "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
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExceptionRevoke"
              }
            }
          }
        }
      }
    },
    "/classification/settings": {
      "get": {
        "operationId": "readSettings",
        "summary": "Read settings (unset = fail closed)",
        "tags": [
          "OHN-42"
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "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": "writeSettings",
        "summary": "Write settings",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Settings"
              }
            }
          }
        }
      }
    },
    "/classification/code-lists/{list}": {
      "get": {
        "operationId": "listCodes",
        "summary": "Read code list",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "resource_category",
                "sensitivity_label",
                "requester_role",
                "purpose",
                "exception_basis"
              ]
            }
          }
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "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-42"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "resource_category",
                "sensitivity_label",
                "requester_role",
                "purpose",
                "exception_basis"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeListUpsert"
              }
            }
          }
        }
      }
    },
    "/classification/maintenance/expire-sweep": {
      "post": {
        "operationId": "expireSweep",
        "summary": "Record expiry of approved exceptions past their time limit",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        }
      }
    },
    "/classification/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Drain outbox (no sink => nothing marked delivered)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        }
      }
    },
    "/classification/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Report catalog",
        "tags": [
          "OHN-42"
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run report",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-42-R001",
                "OHN-42-R002",
                "OHN-42-R003"
              ]
            }
          },
          {
            "name": "purpose",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "label",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 16
            }
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          },
          {
            "name": "period_from",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 10
            }
          },
          {
            "name": "period_to",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 10
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Report (report_id, title, columns, rows, summary, state, generated_at) plus next_cursor"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/classification/reports/{reportId}/export": {
      "post": {
        "operationId": "createExport",
        "summary": "Create signed single-use export",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-42-R001",
                "OHN-42-R002",
                "OHN-42-R003"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "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, patient out of scope, 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)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        }
      }
    },
    "/classification/exports/{token}": {
      "get": {
        "operationId": "fetchExport",
        "summary": "Download export (owner only, single use, 5 min)",
        "tags": [
          "OHN-42"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "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, patient out of scope, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/health/ohn-42": {
      "get": {
        "operationId": "health",
        "summary": "Liveness incl. DB and dependency modes",
        "security": [],
        "responses": {
          "200": {
            "description": "ok"
          },
          "503": {
            "description": "unavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {}
        }
      },
      "Policy": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "resource_category",
          "sensitivity_label",
          "matching_criteria",
          "purpose_limitations",
          "policy_version"
        ],
        "properties": {
          "resource_category": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "sensitivity_label": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "matching_criteria": {
            "type": "string",
            "maxLength": 8192,
            "description": "JSON: {\"codes\":[\"system|code\"],\"code_prefixes\":[\"system|prefix\"]}; at least one entry"
          },
          "purpose_limitations": {
            "type": "string",
            "maxLength": 8192,
            "description": "JSON: {\"allowed_purposes\":[...],\"allowed_roles\":[...],\"on_restricted\":\"redact\"|\"deny\"}; empty lists mean nobody"
          },
          "policy_version": {
            "type": "string",
            "maxLength": 64,
            "minLength": 1
          }
        }
      },
      "Publish": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "expected_version",
          "reason"
        ],
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "Classify": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "resource_ref",
          "resource_category",
          "source_system",
          "codes"
        ],
        "properties": {
          "resource_ref": {
            "type": "string",
            "format": "uuid"
          },
          "resource_category": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "source_system": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "codes": {
            "type": "array",
            "minItems": 1,
            "maxItems": 200,
            "items": {
              "type": "string",
              "pattern": "^[^|\\s]{1,200}\\|[^\\s]{1,100}$"
            }
          }
        }
      },
      "ReviewDecision": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "labels",
          "reason",
          "expected_version"
        ],
        "properties": {
          "labels": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            },
            "maxItems": 20
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Evaluation": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "patient_ref",
          "requester_role",
          "purpose",
          "resources"
        ],
        "properties": {
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "requester_role": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "purpose": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "requested_categories": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            },
            "maxItems": 100
          },
          "mode": {
            "enum": [
              "preview",
              "enforce"
            ],
            "default": "preview",
            "description": "enforce returns only allowed_resource_refs; no counts, labels or reasons, never cacheable"
          },
          "resources": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      },
      "ExceptionRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "patient_ref",
          "sensitivity_type",
          "exception_basis",
          "requester_role",
          "purpose",
          "resource_refs",
          "reason",
          "expires_at"
        ],
        "properties": {
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "sensitivity_type": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "exception_basis": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "requester_role": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "purpose": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "resource_refs": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "Must be in the future and within the configured maximum; no indefinite exceptions"
          }
        }
      },
      "ExceptionReview": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "decision",
          "reason",
          "expected_version"
        ],
        "properties": {
          "decision": {
            "enum": [
              "approve",
              "deny"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "ExceptionRevoke": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "reason",
          "expected_version"
        ],
        "properties": {
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Settings": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "default_label",
          "max_exception_days",
          "approval_reference"
        ],
        "properties": {
          "default_label": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "max_exception_days": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 3650
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3,
            "maxLength": 256
          }
        }
      },
      "CodeListUpsert": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "entries"
        ],
        "properties": {
          "entries": {
            "type": "array",
            "minItems": 1,
            "maxItems": 200,
            "items": {
              "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
                }
              }
            }
          }
        }
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "format"
        ],
        "properties": {
          "format": {
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "type": "object",
            "description": "Report filters (purpose, label, status, source, period_from, period_to); unknown keys are refused with 422"
          }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "report_id": {
            "enum": [
              "OHN-42-R001",
              "OHN-42-R002",
              "OHN-42-R003"
            ]
          },
          "title": {
            "type": "string"
          },
          "columns": {
            "type": "array"
          },
          "rows": {
            "type": "array"
          },
          "summary": {
            "type": "object"
          },
          "state": {
            "enum": [
              "rendered",
              "no_authorized_data"
            ]
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
