{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-22 Legacy Healthcare Integration",
    "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 (legacy_integration). Request bodies are limited to 256 KB. Dependencies (OHN-23 terminology, OHN-21 contract, OHN-03 identity) are called over their contracts and fail closed with 503 dependency_unavailable. The TypeScript-only synthetic sign-in (POST /legacy/synthetic-token) is not part of this contract; tokens come from the platform gateway (purpose legacy_integration)."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "paths": {
    "/legacy/adapters": {
      "post": {
        "operationId": "registerAdapter",
        "summary": "Register adapter (API-001; F001)",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/Adapter"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listAdapters",
        "summary": "Adapter catalog",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "standard",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "case-insensitive name contains"
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "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 (default deny) 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)"
          }
        }
      }
    },
    "/legacy/adapters/{id}": {
      "get": {
        "operationId": "getAdapter",
        "summary": "Adapter with mappings",
        "tags": [
          "OHN-22"
        ],
        "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 (default deny) 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)"
          }
        }
      }
    },
    "/legacy/adapters/{id}/mappings": {
      "post": {
        "operationId": "createMapping",
        "summary": "Draft a mapping version with rules (F002)",
        "tags": [
          "OHN-22"
        ],
        "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_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/MappingCreate"
              }
            }
          }
        }
      }
    },
    "/legacy/mappings/{id}": {
      "get": {
        "operationId": "getMapping",
        "summary": "Mapping with rules and history",
        "tags": [
          "OHN-22"
        ],
        "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 (default deny) 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)"
          }
        }
      }
    },
    "/legacy/mappings/{id}/rules": {
      "post": {
        "operationId": "addRule",
        "summary": "Add a rule to a draft mapping",
        "tags": [
          "OHN-22"
        ],
        "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_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/AddRule"
              }
            }
          }
        }
      }
    },
    "/legacy/mappings/{id}/samples": {
      "post": {
        "operationId": "sampleMapping",
        "summary": "Dry-run a sample message; passing advances draft to sampled",
        "tags": [
          "OHN-22"
        ],
        "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_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/Sample"
              }
            }
          }
        }
      }
    },
    "/legacy/mappings/{id}/transitions": {
      "post": {
        "operationId": "transitionMapping",
        "summary": "Mapping release transition (W002)",
        "tags": [
          "OHN-22"
        ],
        "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_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/MappingTransition"
              }
            }
          }
        }
      }
    },
    "/legacy/messages": {
      "post": {
        "operationId": "ingestMessage",
        "summary": "Ingest a legacy message (API-002; W001). 201 for a new message (published, quarantined or rejected); a duplicate redelivery returns 200 with duplicate=true; same id with other content is 409 message_id_conflict",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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)"
          },
          "200": {
            "description": "Duplicate redelivery of the same external_message_id and content: no second result, the attempt is recorded (duplicate=true)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Message"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listMessages",
        "summary": "Messages / dead-letter queue (status, dlq_state, adapter_id)",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "dlq_state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "adapter_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "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 (default deny) 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)"
          }
        }
      }
    },
    "/legacy/messages/{id}": {
      "get": {
        "operationId": "getMessage",
        "summary": "Message with attempts, errors, history (API-003)",
        "tags": [
          "OHN-22"
        ],
        "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 (default deny) 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)"
          }
        }
      }
    },
    "/legacy/messages/{id}/triage": {
      "post": {
        "operationId": "triage",
        "summary": "Triage a failed message",
        "tags": [
          "OHN-22"
        ],
        "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_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/Triage"
              }
            }
          }
        }
      }
    },
    "/legacy/messages/{id}/correct": {
      "post": {
        "operationId": "correct",
        "summary": "Attach a corrected payload (clinical_mapper only; original retained)",
        "tags": [
          "OHN-22"
        ],
        "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_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/Correct"
              }
            }
          }
        }
      }
    },
    "/legacy/messages/{id}/retry": {
      "post": {
        "operationId": "retry",
        "summary": "Replay a failed message (F003; never re-publishes a published one)",
        "tags": [
          "OHN-22"
        ],
        "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_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/Retry"
              }
            }
          }
        }
      }
    },
    "/legacy/unit-conversions": {
      "get": {
        "operationId": "listUnits",
        "summary": "Unit conversions",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "proposed",
                "approved",
                "rejected"
              ]
            }
          }
        ],
        "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 (default deny) 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": "proposeUnit",
        "summary": "Propose a unit conversion",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/UnitProposal"
              }
            }
          }
        }
      }
    },
    "/legacy/unit-conversions/{id}/decision": {
      "post": {
        "operationId": "decideUnit",
        "summary": "Approve/reject a unit conversion (proposer cannot decide)",
        "tags": [
          "OHN-22"
        ],
        "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_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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/UnitDecision"
              }
            }
          }
        }
      }
    },
    "/legacy/code-lists/{list}": {
      "get": {
        "operationId": "listCodes",
        "summary": "Read code list",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "message_standard",
                "transport"
              ]
            }
          }
        ],
        "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 (default deny) 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-22"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "message_standard",
                "transport"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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"
              }
            }
          }
        }
      }
    },
    "/legacy/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Drain outbox (no sink => nothing marked delivered)",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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)"
          }
        }
      }
    },
    "/legacy/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Report catalog",
        "tags": [
          "OHN-22"
        ],
        "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 (default deny) 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)"
          }
        }
      }
    },
    "/legacy/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run report",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "adapter",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "partner",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "standard",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            }
          },
          {
            "name": "reason",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "period_from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "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",
              "description": "next_cursor of the previous page (100 rows per page)"
            }
          },
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-22-R001",
                "OHN-22-R002",
                "OHN-22-R003"
              ]
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) 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)"
          }
        }
      }
    },
    "/legacy/reports/{reportId}/export": {
      "post": {
        "operationId": "createExport",
        "summary": "Create signed single-use export",
        "tags": [
          "OHN-22"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-22-R001",
                "OHN-22-R002",
                "OHN-22-R003"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            },
            "description": "8 to 128 characters of A-Z a-z 0-9 _ . : -. A 5xx answer releases the key; a replay answers with Idempotent-Replay: true."
          }
        ],
        "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 (default deny) or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition, already published 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"
              }
            }
          }
        }
      }
    },
    "/legacy/exports/{token}": {
      "get": {
        "operationId": "fetchExport",
        "summary": "Download export (the requesting principal only, single use, 5 minutes). Any other caller or token is 404",
        "tags": [
          "OHN-22"
        ],
        "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 (CSV or PDF), once",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "Content-Disposition": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied (default deny) 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)"
          },
          "410": {
            "description": "export_expired (after 5 minutes) or export_consumed (already downloaded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/health/ohn-22": {
      "get": {
        "operationId": "health",
        "summary": "Liveness incl. database ping and dependency modes (public; served at the root, not under /api/ohn/v1)",
        "security": [],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "const": "ok"
                    },
                    "module": {
                      "const": "OHN-22"
                    },
                    "dependencies": {
                      "type": "object",
                      "properties": {
                        "ohn23": {
                          "enum": [
                            "live",
                            "unconfigured"
                          ]
                        },
                        "ohn21": {
                          "enum": [
                            "live",
                            "unconfigured"
                          ]
                        },
                        "identity": {
                          "enum": [
                            "live",
                            "unconfigured"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "unavailable"
          }
        },
        "servers": [
          {
            "url": "/"
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {
            "description": "Validation: {field: issue code} (invalid_type, too_small, too_big, invalid_string, invalid_enum_value, unrecognized_keys under \"_\"), or a domain object"
          }
        }
      },
      "Adapter": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "adapter_name",
          "message_standard",
          "source_org",
          "target_service",
          "transport"
        ],
        "properties": {
          "adapter_name": {
            "type": "string",
            "maxLength": 512,
            "minLength": 1
          },
          "message_standard": {
            "type": "string",
            "description": "Must exist in the jurisdiction message_standard code list",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "source_org": {
            "type": "string",
            "format": "uuid"
          },
          "target_service": {
            "type": "string",
            "format": "uuid"
          },
          "transport": {
            "type": "string",
            "description": "Must exist in the jurisdiction transport code list",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          }
        }
      },
      "Rule": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "source_field",
          "target_fhir_path",
          "transform_expression",
          "terminology_ref",
          "fallback_action"
        ],
        "properties": {
          "source_field": {
            "type": "string",
            "description": "HL7 v2 address, e.g. PID-5.1 or OBX[2]-5",
            "pattern": "^[A-Z][A-Z0-9]{2}(\\[\\d{1,3}\\])?-\\d{1,3}(\\.\\d{1,3})?$"
          },
          "target_fhir_path": {
            "type": "string",
            "pattern": "^[A-Z][A-Za-z]+(\\.[A-Za-z0-9]+(\\[\\w+\\])?)+$",
            "description": "A path of the canonical FHIR contract, e.g. Patient.identifier; checked against OHN-21 at sign-off"
          },
          "transform_expression": {
            "type": "string",
            "description": "One of: copy, trim, upper, lower, hl7_date, number, code, unit(FROM,TO). Not executable code.",
            "minLength": 1,
            "maxLength": 256
          },
          "terminology_ref": {
            "type": "string",
            "format": "uuid"
          },
          "fallback_action": {
            "enum": [
              "reject",
              "quarantine",
              "omit"
            ]
          },
          "mandatory": {
            "type": "boolean",
            "default": false,
            "description": "A mandatory rule may not use fallback omit"
          }
        }
      },
      "MappingCreate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version_label",
          "rules"
        ],
        "properties": {
          "version_label": {
            "type": "string",
            "maxLength": 64
          },
          "rules": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/Rule"
            }
          }
        }
      },
      "AddRule": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "rule",
          "expected_version"
        ],
        "properties": {
          "rule": {
            "$ref": "#/components/schemas/Rule"
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Sample": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sample_message"
        ],
        "properties": {
          "sample_message": {
            "type": "string",
            "maxLength": 200000,
            "minLength": 1
          }
        }
      },
      "MappingTransition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ],
        "properties": {
          "to_state": {
            "enum": [
              "draft",
              "clinical_review",
              "contract_verified",
              "active"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "Message": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "adapter_id",
          "external_message_id",
          "payload"
        ],
        "properties": {
          "adapter_id": {
            "type": "string",
            "format": "uuid"
          },
          "external_message_id": {
            "type": "string",
            "maxLength": 128,
            "minLength": 1
          },
          "payload": {
            "type": "string",
            "maxLength": 1100000,
            "minLength": 1,
            "description": "HL7 v2 text. The service accepts request bodies up to 256 KB (413 payload_too_large above that), so the effective limit is lower than maxLength."
          }
        }
      },
      "Triage": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "investigated_reason",
          "expected_version"
        ],
        "properties": {
          "investigated_reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Correct": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "corrected_payload",
          "reason",
          "expected_version"
        ],
        "properties": {
          "corrected_payload": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1100000
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Retry": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "investigated_reason",
          "validated_mapping_version",
          "operator_ref",
          "expected_version"
        ],
        "properties": {
          "investigated_reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "validated_mapping_version": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "description": "Label of the adapter active mapping; any other label is refused (409 mapping_version_mismatch)"
          },
          "operator_ref": {
            "type": "string",
            "format": "uuid",
            "description": "Must equal the authenticated operator"
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "UnitProposal": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "from_unit",
          "to_unit",
          "factor_numerator",
          "factor_denominator",
          "reference_note"
        ],
        "properties": {
          "from_unit": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32
          },
          "to_unit": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32,
            "description": "Must differ from from_unit"
          },
          "factor_numerator": {
            "type": "string",
            "pattern": "^\\d{1,18}(\\.\\d{1,12})?$",
            "description": "Positive decimal"
          },
          "factor_denominator": {
            "type": "string",
            "pattern": "^\\d{1,18}(\\.\\d{1,12})?$",
            "description": "Positive decimal"
          },
          "reference_note": {
            "type": "string",
            "minLength": 10,
            "maxLength": 1024
          }
        }
      },
      "UnitDecision": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "decision",
          "reason",
          "expected_version"
        ],
        "properties": {
          "decision": {
            "enum": [
              "approved",
              "rejected"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "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": {
            "$ref": "#/components/schemas/ReportFilters"
          }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "report_id": {
            "enum": [
              "OHN-22-R001",
              "OHN-22-R002",
              "OHN-22-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"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ReportFilters": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "adapter": {
            "type": "string",
            "format": "uuid"
          },
          "partner": {
            "type": "string",
            "format": "uuid",
            "description": "source_org of the adapter"
          },
          "standard": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "reason": {
            "type": "string",
            "maxLength": 64,
            "description": "R002 failure reason code"
          },
          "status": {
            "type": "string",
            "maxLength": 32,
            "description": "R003 outcome"
          },
          "period_from": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "period_to": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
            "description": "Not before period_from (422 after_period_to)"
          }
        }
      },
      "Receipt": {
        "type": "object",
        "properties": {
          "receipt_id": {
            "type": "string",
            "format": "uuid"
          },
          "committed_at": {
            "type": "string",
            "format": "date-time"
          },
          "aggregate_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "enum": [
              "committed",
              "denied"
            ]
          }
        }
      }
    }
  }
}
