openapi: 3.1.0
info:
  title: OHN-47 Disaster Recovery and Business Continuity
  version: 1.0.0
  description: >-
    Records and verifies backups, restore drills, failovers, recovery objectives and continuity plans per jurisdiction.
    Synthetic records only: the service never performs real backups, restores or destructive actions.
    Recovery objectives (RPO/RTO) are approved records; drill interval and export signing are configuration
    (OHN47_DRILL_INTERVAL_DAYS, OHN47_EXPORT_SIGNING_KEY) and fail closed when unset.
    Every write needs an Idempotency-Key and returns an audit receipt; receipts are forwarded to OHN-18 when configured.
    Events published from ohn47_outbox: backup.failed, restore.drill.passed, failover.initiated.
jsonSchemaDialect: https://json-schema.org/draft/2020-12/schema
servers:
  - url: /
security:
  - bearerAuth: []
components:
  securitySchemes:
    bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT }
  parameters:
    IdempotencyKey: { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 1, maxLength: 255 } }
    Id: { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    PageSize: { name: page_size, in: query, schema: { type: integer, minimum: 1, maximum: 100 } }
    Cursor: { name: cursor, in: query, schema: { type: string } }
  responses:
    Problem: { description: Error (401 unauthenticated, 403 denied_by_policy, 404 not_found, 409 concurrent_mutation/invalid_transition/idempotency_conflict, 422 domain_validation_failed/domain_refusal/separation_of_duties, 429 rate_limited, 503 jurisdiction_unavailable/dependency_unavailable/not_configured), content: { application/json: { schema: { $ref: '#/components/schemas/Problem' } } } }
    Committed: { description: Committed with receipt (202 when the OHN-18 audit copy failed and is pending reconciliation), content: { application/json: { schema: { type: object, required: [receipt], properties: { receipt: { $ref: '#/components/schemas/Receipt' } } } } } }
  schemas:
    Problem: { type: object, required: [error], description: 'Reference fields error, message and details (for 422 the first failing check per top-level field as a zod issue code: invalid_type, too_small, too_big, invalid_string, invalid_enum_value, invalid_union_discriminator; unknown keys under _ as unrecognized_keys) plus the platform problem+json superset.', properties: { error: { type: string }, message: { type: string }, details: {}, type: { type: string }, title: { type: string }, status: { type: integer }, detail: { type: string }, trace_id: { type: string } } }
    Receipt:
      type: object
      required: [receipt_id, committed_at, aggregate_id, aggregate_type, version, status, audit_forwarding, policy_version]
      properties:
        receipt_id: { type: string, format: uuid }
        committed_at: { type: string, format: date-time }
        aggregate_id: { type: string, format: uuid }
        aggregate_type: { type: string }
        version: { type: integer }
        status: { const: committed }
        audit_forwarding: { enum: [pending, forwarded, failed] }
        policy_version: { type: string }
    DataClass: { enum: [identity, clinical_record, consent, audit_log, cryptographic_material, operational_metadata] }
    Scenario: { enum: [full_restore, point_in_time_recovery, single_service_restore, regional_failover, ransomware_recovery, key_loss_recovery] }
    Sha256: { type: string, pattern: '^[0-9a-f]{64}$' }
    TransitionBase:
      type: object
      required: [expected_version, evidence_ref, reason, to_state]
      properties:
        expected_version: { type: integer, minimum: 1 }
        evidence_ref: { type: string, format: uuid }
        reason: { type: string, minLength: 10, maxLength: 4096 }
    RecoveryObjectiveCommand:
      description: OHN-47-F001 Recovery objective policy.
      type: object
      additionalProperties: false
      required: [service, data_class, rpo_seconds, rto_minutes, jurisdiction_id, approval_ref]
      properties:
        service: { type: string, format: uuid }
        data_class: { $ref: '#/components/schemas/DataClass' }
        rpo_seconds: { type: integer, minimum: 0, maximum: 2147483647 }
        rto_minutes: { type: integer, minimum: 0, maximum: 2147483647 }
        jurisdiction_id: { type: string, format: uuid }
        approval_ref: { type: string, format: uuid }
    RestoreDrillCommand:
      description: OHN-47-F002 Restore drill request.
      type: object
      additionalProperties: false
      required: [service, backup_snapshot_ref, isolated_environment, scenario, drill_owner]
      properties:
        service: { type: string, format: uuid }
        backup_snapshot_ref: { type: string, format: uuid }
        isolated_environment: { type: string, format: uuid }
        scenario: { $ref: '#/components/schemas/Scenario' }
        drill_owner: { type: string, format: uuid }
    FailoverApprovalCommand:
      description: OHN-47-F003 Failover approval.
      type: object
      additionalProperties: false
      required: [incident_ref, target_region, data_loss_assessment, decision, approver, expected_version]
      properties:
        incident_ref: { type: string, format: uuid }
        target_region: { type: string, minLength: 1, maxLength: 512, description: Trimmed; must differ (case-insensitively) from the failed region. }
        data_loss_assessment: { type: string, minLength: 1, maxLength: 8192 }
        decision: { enum: [approve, reject] }
        approver: { type: string, format: uuid, description: Must equal the authenticated incident commander. }
        expected_version: { type: integer, minimum: 1 }
    BackupRunCommand:
      type: object
      additionalProperties: false
      required: [service, data_class, snapshot_ref, source_region, storage_location_class, content_hash, backup_started_at]
      properties:
        service: { type: string, format: uuid }
        data_class: { $ref: '#/components/schemas/DataClass' }
        snapshot_ref: { type: string, format: uuid }
        source_region: { type: string, minLength: 1, maxLength: 512 }
        storage_location_class: { enum: [offsite, on_host_only] }
        content_hash: { $ref: '#/components/schemas/Sha256' }
        backup_started_at: { type: string, format: date-time, description: 'UTC with a trailing Z (zod datetime()).' }
    FailoverDeclarationCommand:
      type: object
      additionalProperties: false
      required: [service, data_class, incident_ref, source_region, is_exercise, outage_detected_at]
      properties:
        service: { type: string, format: uuid }
        data_class: { $ref: '#/components/schemas/DataClass' }
        incident_ref: { type: string, format: uuid, description: One failover per incident and service. }
        source_region: { type: string, minLength: 1, maxLength: 512 }
        is_exercise: { type: boolean }
        outage_detected_at: { type: string, format: date-time }
    ContinuityPlanCommand:
      type: object
      additionalProperties: false
      required: [service, scenario, title, playbook_ref, drill_owner, review_due_at]
      properties:
        service: { type: string, format: uuid }
        scenario: { $ref: '#/components/schemas/Scenario' }
        title: { type: string, minLength: 3, maxLength: 512 }
        playbook_ref: { type: string, format: uuid }
        drill_owner: { type: string, format: uuid }
        isolated_environment: { type: string, format: uuid }
        backup_snapshot_ref: { type: string, format: uuid }
        review_due_at: { type: string, format: date-time }
    BackupTransition:
      description: "to_state: encrypted (encryption_key_ref, checked active in OHN-45) | offsite_written (offsite_region != source, offsite_location_ref; on_host_only refused) | hash_verified (observed_hash; mismatch moves to failed) | recoverability_sampled (restore_drill_ref of a signed-off passed drill) | failed."
      allOf: [{ $ref: '#/components/schemas/TransitionBase' }]
    DrillTransition:
      description: "to_state: isolated_restore (restore_started_at) | data_integrity_checked (restore_completed_at, identity_check, consent_check, record_integrity_check) | rto_rpo_measured (measured_rpo_seconds, measured_rto_minutes >= observed restore, issue_count, issues) | signed_off (sign_off_decision passed|failed; incident commander, not the requester; passed only when all checks pass within objective) | failed."
      allOf: [{ $ref: '#/components/schemas/TransitionBase' }]
    FailoverTransition:
      description: "to_state: failover (requires approved decision) | consistency_reconciled (acknowledged_issuance_count must equal reconciled_issuance_count, measured_rpo_seconds, measured_rto_minutes, issue_count) | service_reopened."
      allOf: [{ $ref: '#/components/schemas/TransitionBase' }]
paths:
  /api/ohn/v1/dr/health:
    get: { operationId: ohn47_health, security: [], description: 'Unauthenticated: status, export_signing_configured, drill_interval_configured, policy_version.', responses: { '200': { description: Service health } } }
  /health/ohn-47:
    get: { operationId: ohn47_platformHealth, security: [], description: Database probe and dependency modes (OHN-01, OHN-18, OHN-45)., responses: { '200': { description: Healthy }, '503': { description: Database unavailable } } }
  /api/ohn/v1/dr/code-lists:
    get: { operationId: ohn47_getCodeLists, responses: { '200': { description: Versioned code lists and policy state } } }
  /api/ohn/v1/dr/recovery-objectives:
    get: { operationId: ohn47_listRecoveryObjectives, description: OHN-47-API-003, parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { name: status, in: query, schema: { enum: [active, superseded, all] } }, { name: service, in: query, schema: { type: string, format: uuid } }, { name: data_class, in: query, schema: { $ref: '#/components/schemas/DataClass' } }], responses: { '200': { description: Page of objectives }, default: { $ref: '#/components/responses/Problem' } } }
    post: { operationId: ohn47_approveRecoveryObjective, description: OHN-47-F001-SUBMIT; incident_commander only; supersedes the active objective for the same service/data class., parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/RecoveryObjectiveCommand' } } } }, responses: { '201': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/recovery-objectives/{id}:
    get: { operationId: ohn47_getRecoveryObjective, parameters: [{ $ref: '#/components/parameters/Id' }], responses: { '200': { description: Objective with history }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/backups:
    get: { operationId: ohn47_listBackups, description: OHN-47-API-001; page plus KPIs, status distribution, 14-day trend and exception worklist., parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { name: status, in: query, schema: { type: string } }, { name: service, in: query, schema: { type: string, format: uuid } }], responses: { '200': { description: Backup monitor }, default: { $ref: '#/components/responses/Problem' } } }
    post: { operationId: ohn47_registerBackup, parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/BackupRunCommand' } } } }, responses: { '201': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/backups/{id}:
    get: { operationId: ohn47_getBackup, parameters: [{ $ref: '#/components/parameters/Id' }], responses: { '200': { description: Backup with history }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/backups/{id}/transitions:
    post: { operationId: ohn47_transitionBackup, description: Workflow OHN-47-W001., parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/BackupTransition' } } } }, responses: { '200': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/restore-drills:
    get: { operationId: ohn47_listRestoreDrills, parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { name: status, in: query, schema: { type: string } }, { name: service, in: query, schema: { type: string, format: uuid } }], responses: { '200': { description: Page of drills }, default: { $ref: '#/components/responses/Problem' } } }
    post: { operationId: ohn47_requestRestoreDrill, description: OHN-47-API-002 / OHN-47-F002-SUBMIT; idempotent; needs a hash-verified backup and an approved objective (503 not_configured otherwise)., parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/RestoreDrillCommand' } } } }, responses: { '201': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/restore-drills/{id}:
    get: { operationId: ohn47_getRestoreDrill, parameters: [{ $ref: '#/components/parameters/Id' }], responses: { '200': { description: Drill with history }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/restore-drills/{id}/evidence:
    get: { operationId: ohn47_getRestoreDrillEvidence, parameters: [{ $ref: '#/components/parameters/Id' }], responses: { '200': { description: Drill, backup, objective, checks, history and audit receipts }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/restore-drills/{id}/transitions:
    post: { operationId: ohn47_transitionRestoreDrill, description: Workflow OHN-47-W002; signed_off requires incident_commander., parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/DrillTransition' } } } }, responses: { '200': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/failovers:
    get: { operationId: ohn47_listFailovers, parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { name: status, in: query, schema: { type: string } }, { name: service, in: query, schema: { type: string, format: uuid } }], responses: { '200': { description: Page of failovers }, default: { $ref: '#/components/responses/Problem' } } }
    post: { operationId: ohn47_declareFailover, parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/FailoverDeclarationCommand' } } } }, responses: { '201': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/failovers/{id}:
    get: { operationId: ohn47_getFailover, parameters: [{ $ref: '#/components/parameters/Id' }], responses: { '200': { description: Failover with history and audit receipts }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/failovers/{id}/decision:
    post: { operationId: ohn47_decideFailover, description: OHN-47-F003-SUBMIT; incident_commander only., parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/FailoverApprovalCommand' } } } }, responses: { '200': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/failovers/{id}/transitions:
    post: { operationId: ohn47_transitionFailover, description: Workflow OHN-47-W003., parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/FailoverTransition' } } } }, responses: { '200': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/continuity-plans:
    get: { operationId: ohn47_listContinuityPlans, parameters: [{ name: service, in: query, schema: { type: string, format: uuid } }], responses: { '200': { description: Active plans } } }
    post: { operationId: ohn47_registerContinuityPlan, parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ContinuityPlanCommand' } } } }, responses: { '201': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/simulations/regional-data-loss:
    get: { operationId: ohn47_simulateRegionalDataLoss, description: Read-only; writes nothing., parameters: [{ name: lost_region, in: query, required: true, schema: { type: string } }, { name: as_of, in: query, schema: { type: string, format: date-time } }], responses: { '200': { description: Simulation }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/audit-records:
    get: { operationId: ohn47_listAuditRecords, parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { name: resource_id, in: query, schema: { type: string, format: uuid } }], responses: { '200': { description: Audit receipts in scope } } }
  /api/ohn/v1/dr/events:
    get: { operationId: ohn47_listOutboxEvents, responses: { '200': { description: Latest 100 outbox events in scope } } }
  /api/ohn/v1/dr/reports/{id}:
    get: { operationId: ohn47_getReport, description: OHN-47-R001 | OHN-47-R002 | OHN-47-R003., parameters: [{ name: id, in: path, required: true, schema: { enum: [OHN-47-R001, OHN-47-R002, OHN-47-R003] } }, { name: jurisdiction, in: query, schema: { type: string, format: uuid } }, { name: service, in: query, schema: { type: string, format: uuid } }, { name: period_from, in: query, schema: { type: string, format: date-time } }, { name: period_to, in: query, schema: { type: string, format: date-time } }, { name: criticality, in: query, schema: { enum: [critical, major, minor] } }], responses: { '200': { description: Report with metrics, definitions and provenance }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/reports/{id}/export:
    post: { operationId: ohn47_createExport, description: Signed (HMAC) CSV/PDF; 503 not_configured without OHN47_EXPORT_SIGNING_KEY., parameters: [{ name: id, in: path, required: true, schema: { type: string } }, { $ref: '#/components/parameters/IdempotencyKey' }], requestBody: { required: true, content: { application/json: { schema: { type: object, required: [format], properties: { format: { enum: [csv, pdf] } } } } } }, responses: { '201': { $ref: '#/components/responses/Committed' }, default: { $ref: '#/components/responses/Problem' } } }
  /api/ohn/v1/dr/exports/{token}:
    get: { operationId: ohn47_downloadExport, description: One-time, same principal, expires after OHN47_EXPORT_TTL_SECONDS., parameters: [{ name: token, in: path, required: true, schema: { type: string } }], responses: { '200': { description: File with X-OHN-Export-Signature }, '404': { $ref: '#/components/responses/Problem' } } }
