openapi: 3.1.0
info:
  title: OHN-20 Privacy and Information Governance
  version: 1.0.0
  description: |
    Register of processing activities, legal roles (controller / processor chain), approved purposes, privacy impact assessments,
    privacy notices, cross-border transfer reviews and privacy incidents, plus jurisdiction privacy configuration, reports with signed
    one-time exports, and machine contracts for OHN-48 (retention decisions) and gateways (transfer decisions).
    All routes live under /api/ohn/v1/privacy-governance and are scoped to the token jurisdiction. Every POST requires an Idempotency-Key header
    (1-255 characters; a replay returns the stored answer; reuse with another body is 409 idempotency_conflict). Version-checked writes take
    expected_version and answer 409 concurrent_mutation when stale. Default deny. Policy values (code lists, incident response window,
    transfer corridors) are jurisdiction configuration: when absent the operation fails closed (503 not_configured, setting names what is missing).
    Roles: privacy_officer and jurisdiction_administrator (stewards), privacy_service (read-only machine role for the service reads),
    unauthorized_viewer (always refused). Policy configuration and outbox dispatch are jurisdiction_administrator only.
    Java: tokens are issued by the gateway (ES256, audience ohn-20); the TypeScript synthetic sign-in helper is not part of this contract.
    Synthetic data only.
servers:
  - url: https://opeshealthnetwork.com
security:
  - bearerAuth: []
tags:
  - name: config
  - name: register
  - name: roles
  - name: purposes
  - name: assessments
  - name: transfers
  - name: notices
  - name: incidents
  - name: reports
  - name: operations
paths:
  /health/ohn-20:
    get:
      operationId: ohn20_health
      security: []
      responses:
        '200': { description: 'Database reachable; dependency modes and flags', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '503': { description: Database unavailable }
  /api/ohn/v1/privacy-governance/health:
    get:
      operationId: ohn20_externalHealth
      security: []
      responses:
        '200': { description: 'Liveness', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/config:
    get:
      operationId: ohn20_getConfig
      tags: [config]
      description: Controlled values, policy settings, corridors, retention rules, readiness flags and the list of missing settings.
      responses:
        '200': { description: 'Jurisdiction configuration', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '403': { $ref: '#/components/responses/Denied' }
  /api/ohn/v1/privacy-governance/config/controlled-values:
    post:
      operationId: ohn20_upsertControlledValue
      tags: [config]
      description: jurisdiction_administrator. Creates or updates one code of a jurisdiction code list; an update increments version; emits privacy.policy.changed.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ControlledValueCommand' } } } }
      responses:
        '201': { description: 'Controlled value with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/config/policy-settings:
    post:
      operationId: ohn20_setPolicySettings
      tags: [config]
      description: jurisdiction_administrator. expected_version 0 creates the settings; later writes need the current policy_version. incident_response_hours is required but may be null (clock not configured).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/PolicySettingsCommand' } } } }
      responses:
        '200': { description: 'Policy settings with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/config/transfer-corridors:
    post:
      operationId: ohn20_setTransferCorridor
      tags: [config]
      description: jurisdiction_administrator. Approves or suspends a corridor to a destination jurisdiction. The destination must differ from the token jurisdiction; approving needs the destination active in OHN-01.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/TransferCorridorCommand' } } } }
      responses:
        '201': { description: 'Corridor with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/config/retention-rules:
    post:
      operationId: ohn20_setRetentionRule
      tags: [config]
      description: jurisdiction_administrator. Sets the retention rule of a record class; legal_basis must be an active legal_basis code.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/RetentionRuleCommand' } } } }
      responses:
        '201': { description: 'Retention rule with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/retention-decisions:
    get:
      operationId: ohn20_getRetentionDecision
      tags: [config]
      description: OHN-48 contract ohn20.retention-decision/1.0.0. Always 200 with permit or deny; every decision is audited and decision_ref is its receipt id. Unknown query parameters are refused (422).
      parameters:
        - { name: jurisdiction_id, in: query, schema: { type: string }, description: 'Required uuid; must equal the token jurisdiction (403 jurisdiction_out_of_scope)' }
        - { name: organization_id, in: query, schema: { type: string }, description: 'Required uuid' }
        - { name: record_class, in: query, schema: { type: string }, description: 'Required code' }
        - { name: operation, in: query, schema: { type: string }, description: 'Required: policy_approval or disposal' }
        - { name: retention_years, in: query, schema: { type: string }, description: 'Required number 0..200' }
        - { name: record_set_ref, in: query, schema: { type: string }, description: 'Optional uuid' }
      responses:
        '200': { description: 'Decision', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/dashboard:
    get:
      operationId: ohn20_getDashboard
      tags: [operations]
      responses:
        '200': { description: 'KPIs, distributions, 30-day trend, exceptions and dependency modes', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/processing-register:
    get:
      operationId: ohn20_listProcessingRegister
      tags: [register]
      description: OHN-20-API-001. Paged register of processing activities (service reads allowed for privacy_service).
      parameters:
        - { name: limit, in: query, schema: { type: string }, description: 'Clamped to 1..100, default 25' }
        - { name: offset, in: query, schema: { type: string } }
        - { name: status, in: query, schema: { type: string } }
        - { name: purpose, in: query, schema: { type: string } }
        - { name: controller, in: query, schema: { type: string } }
        - { name: retention_policy, in: query, schema: { type: string } }
        - { name: q, in: query, schema: { type: string }, description: 'Case-insensitive search in data_categories' }
        - { name: sort, in: query, schema: { type: string }, description: 'created_at (default), updated_at, status, processing_purpose' }
        - { name: order, in: query, schema: { type: string }, description: 'asc or desc (default)' }
      responses:
        '200': { description: 'Page with total', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/processing-activities:
    post:
      operationId: ohn20_createProcessingActivity
      tags: [register]
      description: Form OHN-20-F001. Registers an activity as draft (W001).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ProcessingActivityCommand' } } } }
      responses:
        '201': { description: 'Activity with receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/processing-activities/{id}:
    get:
      operationId: ohn20_getProcessingActivity
      tags: [register]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses:
        '200': { description: 'Activity with roles, assessments, transfers, history (reduced for privacy_service), next_state and lifecycle', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/privacy-governance/processing-activities/{id}/transitions:
    post:
      operationId: ohn20_transitionProcessingActivity
      tags: [register]
      description: W001 draft, lawful_basis_reviewed, risk_assessed, authorized, monitored; one step at a time with guards; authorizing needs OHN-07 membership and an OHN-16 permit.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/WorkflowTransitionCommand' } } } }
      responses:
        '200': { description: 'Transition committed with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/retention-references/{retention}:
    get:
      operationId: ohn20_getRetentionReferences
      tags: [register]
      description: OHN-48 contract. Activities that rely on a retention schedule.
      parameters: [{ name: retention, in: path, required: true, schema: { type: string } }]
      responses:
        '200': { description: 'References', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/privacy-governance/legal-roles:
    get:
      operationId: ohn20_listLegalRoles
      tags: [roles]
      parameters: [{ name: processing_activity_id, in: query, schema: { type: string } }]
      responses:
        '200': { description: 'Assignments (max 500)', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
    post:
      operationId: ohn20_assignLegalRole
      tags: [roles]
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/LegalRoleCommand' } } } }
      responses:
        '201': { description: 'Assignment with receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/legal-roles/{id}/revoke:
    post:
      operationId: ohn20_revokeLegalRole
      tags: [roles]
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/VersionedReasonCommand' } } } }
      responses:
        '200': { description: 'Revoked assignment with receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
  /api/ohn/v1/privacy-governance/role-matrix:
    get:
      operationId: ohn20_getRoleMatrix
      tags: [roles]
      responses:
        '200': { description: 'Activities by legal role with gaps (accountable_controller_missing, processor_chain_undocumented)', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/purposes:
    get:
      operationId: ohn20_listPurposes
      tags: [purposes]
      responses:
        '200': { description: 'Approved purposes (max 500)', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
    post:
      operationId: ohn20_approvePurpose
      tags: [purposes]
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/DisclosurePurposeCommand' } } } }
      responses:
        '201': { description: 'Purpose with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/purposes/{id}/retire:
    post:
      operationId: ohn20_retirePurpose
      tags: [purposes]
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/VersionedReasonCommand' } } } }
      responses:
        '200': { description: 'Retired purpose with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
  /api/ohn/v1/privacy-governance/assessments:
    get:
      operationId: ohn20_listAssessments
      tags: [assessments]
      description: OHN-20-P002 list.
      parameters:
        - { name: limit, in: query, schema: { type: string } }
        - { name: offset, in: query, schema: { type: string } }
        - { name: approval_state, in: query, schema: { type: string } }
        - { name: risk_rating, in: query, schema: { type: string } }
        - { name: processing_activity_id, in: query, schema: { type: string } }
      responses:
        '200': { description: 'Page with total', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
    post:
      operationId: ohn20_createAssessment
      tags: [assessments]
      description: "Form OHN-20-F002 (OHN-20-API-002). Approval is never client-asserted; only draft or submitted are accepted."
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/AssessmentCommand' } } } }
      responses:
        '201': { description: 'Assessment with receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/assessments/{id}:
    get:
      operationId: ohn20_getAssessment
      tags: [assessments]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses:
        '200': { description: 'Assessment with activity, previous assessments, history and can_decide', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/privacy-governance/assessments/{id}/decision:
    post:
      operationId: ohn20_decideAssessment
      tags: [assessments]
      description: Submit, approve or reject. The reviewer must differ from the submitter (403 separation_of_duties). Approving needs risk_rating and emits privacy.assessment.approved.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/AssessmentDecisionCommand' } } } }
      responses:
        '200': { description: 'Assessment with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/transfers:
    get:
      operationId: ohn20_listTransfers
      tags: [transfers]
      parameters:
        - { name: limit, in: query, schema: { type: string } }
        - { name: offset, in: query, schema: { type: string } }
        - { name: state, in: query, schema: { type: string } }
        - { name: outcome, in: query, schema: { type: string } }
        - { name: destination, in: query, schema: { type: string } }
      responses:
        '200': { description: 'Page with total', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/transfers/review:
    post:
      operationId: ohn20_requestTransferReview
      tags: [transfers]
      description: Form OHN-20-F003 (OHN-20-API-003). Opens W002 at requested; origin_jurisdiction must equal the token jurisdiction.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/TransferReviewCommand' } } } }
      responses:
        '201': { description: 'Transfer review with receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/transfers/{id}:
    get:
      operationId: ohn20_getTransfer
      tags: [transfers]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses:
        '200': { description: 'Transfer with corridor, activity, history, next_state and lifecycle', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/privacy-governance/transfers/{id}/transitions:
    post:
      operationId: ohn20_transitionTransfer
      tags: [transfers]
      description: W002 requested, residency_checked, legal_approval, purpose_limited, logged_or_denied. decision deny closes the review as denied. The final authorization needs an OHN-16 permit and (by policy) a distinct authorizer.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/WorkflowTransitionCommand' } } } }
      responses:
        '200': { description: 'Transfer with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/transfer-decisions:
    get:
      operationId: ohn20_getTransferDecision
      tags: [transfers]
      description: Machine contract for gateways. Always 200 with allow or deny (default deny).
      parameters:
        - { name: destination_jurisdiction, in: query, schema: { type: string }, description: 'Required uuid' }
        - { name: processing_activity_id, in: query, schema: { type: string }, description: 'Required uuid' }
      responses:
        '200': { description: 'Decision', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/notices:
    get:
      operationId: ohn20_listNotices
      tags: [notices]
      parameters: [{ name: status, in: query, schema: { type: string } }]
      responses:
        '200': { description: 'Notices (max 500)', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
    post:
      operationId: ohn20_createNotice
      tags: [notices]
      description: Form OHN-20-F004. A notice version and language is unique per organization (409 duplicate).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/PrivacyNoticeCommand' } } } }
      responses:
        '201': { description: 'Notice with receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/notices/{id}:
    get:
      operationId: ohn20_getNotice
      tags: [notices]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses:
        '200': { description: 'Notice with history, next_state and lifecycle', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/privacy-governance/notices/{id}/transitions:
    post:
      operationId: ohn20_transitionNotice
      tags: [notices]
      description: draft, impact_reviewed, legally_reviewed, effective, retired; effective needs an active publication channel; effective and retired emit privacy.policy.changed.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/WorkflowTransitionCommand' } } } }
      responses:
        '200': { description: 'Notice with receipt and events', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/incidents:
    get:
      operationId: ohn20_listIncidents
      tags: [incidents]
      responses:
        '200': { description: 'Incidents (max 500) with clock_status', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
    post:
      operationId: ohn20_reportIncident
      tags: [incidents]
      description: Opens W003 at incident_reported. The response clock exists only when the jurisdiction configured incident_response_hours.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/IncidentCommand' } } } }
      responses:
        '201': { description: 'Incident with receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/incidents/{id}:
    get:
      operationId: ohn20_getIncident
      tags: [incidents]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses:
        '200': { description: 'Incident with history, next_state and lifecycle', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/privacy-governance/incidents/{id}/transitions:
    post:
      operationId: ohn20_transitionIncident
      tags: [incidents]
      description: W003 incident_reported, triaged, impact_evaluated, notification_decision, remediated. notification_required must be decided explicitly at notification_decision.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/WorkflowTransitionCommand' } } } }
      responses:
        '200': { description: 'Incident with receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/privacy-governance/data-flows:
    get:
      operationId: ohn20_listDataFlows
      tags: [register]
      description: OHN-20-P005. Activities as nodes and edges (controller, processor, sub-processors, cross-border destinations).
      parameters:
        - { name: limit, in: query, schema: { type: string } }
        - { name: offset, in: query, schema: { type: string } }
        - { name: status, in: query, schema: { type: string } }
        - { name: q, in: query, schema: { type: string } }
        - { name: destination, in: query, schema: { type: string } }
      responses:
        '200': { description: 'Page with total', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/reports:
    get:
      operationId: ohn20_listReports
      tags: [reports]
      responses:
        '200': { description: 'Report definitions', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/reports/{id}:
    get:
      operationId: ohn20_getReport
      tags: [reports]
      parameters:
        - { $ref: '#/components/parameters/ReportId' }
        - { name: purpose, in: query, schema: { type: string } }
        - { name: controller, in: query, schema: { type: string } }
        - { name: status, in: query, schema: { type: string } }
        - { name: risk, in: query, schema: { type: string } }
        - { name: from, in: query, schema: { type: string } }
        - { name: to, in: query, schema: { type: string } }
        - { name: country, in: query, schema: { type: string } }
      responses:
        '200': { description: 'Report rows, metrics, metric definitions and provenance', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/privacy-governance/reports/{id}/export:
    post:
      operationId: ohn20_createExport
      tags: [reports]
      parameters: [{ $ref: '#/components/parameters/ReportId' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ExportCommand' } } } }
      responses:
        '201': { description: 'HMAC-signed export with one-time retrieval path', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '503': { description: 'not_configured (export signing key missing); nothing generated' }
  /api/ohn/v1/privacy-governance/exports/{token}:
    get:
      operationId: ohn20_downloadExport
      tags: [reports]
      description: One time, five minutes, bound to the requesting principal and jurisdiction.
      parameters: [{ name: token, in: path, required: true, schema: { type: string } }]
      responses:
        '200':
          description: CSV or PDF body with X-OHN20-Signature header
          content:
            text/csv: { schema: { type: string, format: binary } }
            application/pdf: { schema: { type: string, format: binary } }
        '404': { $ref: '#/components/responses/NotFound' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/privacy-governance/audit:
    get:
      operationId: ohn20_listAudit
      tags: [operations]
      parameters:
        - { name: limit, in: query, schema: { type: string } }
        - { name: offset, in: query, schema: { type: string } }
        - { name: resource_id, in: query, schema: { type: string } }
      responses:
        '200': { description: 'Audit receipts of the jurisdiction (append-only)', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/outbox:
    get:
      operationId: ohn20_listOutbox
      tags: [operations]
      responses:
        '200': { description: 'Pending and delivered events and the OHN-24 sink mode', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
  /api/ohn/v1/privacy-governance/outbox/dispatch:
    post:
      operationId: ohn20_dispatchOutbox
      tags: [operations]
      description: jurisdiction_administrator. At-least-once relay of pending events to OHN-24; a failed delivery stays pending. The body is optional.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: false, content: { application/json: { schema: { $ref: '#/components/schemas/DispatchCommand' } } } }
      responses:
        '200': { description: 'delivered, failed, pending_after and receipt', content: { application/json: { schema: { $ref: '#/components/schemas/JsonObject' } } } }
        '503': { $ref: '#/components/responses/Unavailable' }
components:
  securitySchemes:
    bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT, description: 'Gateway-issued ES256 token (audience ohn-20) carrying role, jurisdiction, organization_id and a privacy-governance purpose' }
  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 }, description: 'uuid; anything else is 404' }
    ReportId: { name: id, in: path, required: true, schema: { type: string }, description: 'OHN-20-R001, OHN-20-R002 or OHN-20-R003; anything else is 404' }
  responses:
    Denied: { description: 'denied_by_policy, jurisdiction_out_of_scope, separation_of_duties or pdp_denied' }
    NotFound: { description: 'not_found' }
    Validation: { description: 'domain_validation_failed (details per field), workflow_refused (guard), organization_not_member, jurisdiction_not_active or code_not_recognized' }
    Conflict: { description: 'concurrent_mutation, invalid_transition, duplicate, idempotency_conflict or request_in_progress' }
    Unavailable: { description: 'not_configured (setting names what is missing) or dependency_unavailable (OHN-01, OHN-07, OHN-16, OHN-24); nothing written' }
  schemas:
    JsonObject: { type: object, additionalProperties: true }
    Code: { type: string, pattern: '^[a-z][a-z0-9_]{1,63}$' }
    ControlledValueCommand:
      type: object
      additionalProperties: false
      required: [list_name, code, label_en, label_fr]
      properties:
        list_name: { enum: [processing_purpose, legal_basis, publication_channel, volume_class] }
        code: { $ref: '#/components/schemas/Code' }
        label_en: { type: string, minLength: 1, maxLength: 256 }
        label_fr: { type: string, minLength: 1, maxLength: 256 }
        active: { type: boolean, default: true }
    PolicySettingsCommand:
      type: object
      additionalProperties: false
      required: [expected_version, require_distinct_authorizer]
      properties:
        expected_version: { type: integer, minimum: 0 }
        incident_response_hours: { type: [integer, 'null'], minimum: 1, maximum: 8760, description: "Must be present; null means the response clock is not configured (checked by the service, since the generated model cannot tell absent from null)" }
        require_distinct_authorizer: { type: boolean }
    TransferCorridorCommand:
      type: object
      additionalProperties: false
      required: [destination_jurisdiction, legal_authority_ref, safeguard_ref]
      properties:
        destination_jurisdiction: { type: string, format: uuid }
        legal_authority_ref: { type: string, format: uuid }
        safeguard_ref: { type: string, format: uuid }
        status: { enum: [approved, suspended], default: approved }
        valid_until: { type: string, pattern: '^\d{4}-\d{2}-\d{2}$' }
    RetentionRuleCommand:
      type: object
      additionalProperties: false
      required: [record_class, legal_basis, min_retention_years]
      properties:
        record_class: { $ref: '#/components/schemas/Code' }
        legal_basis: { $ref: '#/components/schemas/Code' }
        min_retention_years: { type: integer, minimum: 0, maximum: 200 }
        status: { enum: [active, retired], default: active }
    ProcessingActivityCommand:
      type: object
      additionalProperties: false
      required: [jurisdiction_id, controller_org, processing_purpose, legal_basis, data_categories, retention_policy]
      properties:
        jurisdiction_id: { type: string, format: uuid }
        controller_org: { type: string, format: uuid }
        processor_org: { type: string, format: uuid, description: Must differ from controller_org }
        processing_purpose: { $ref: '#/components/schemas/Code' }
        legal_basis: { $ref: '#/components/schemas/Code' }
        data_categories: { type: string, minLength: 1, maxLength: 8192 }
        retention_policy: { type: string, format: uuid }
    WorkflowTransitionCommand:
      type: object
      additionalProperties: false
      required: [expected_version, to_state, evidence_ref, reason]
      properties:
        expected_version: { type: integer, minimum: 1 }
        to_state: { type: string, minLength: 1, maxLength: 64 }
        evidence_ref: { type: string, format: uuid }
        reason: { type: string, minLength: 10, maxLength: 4096 }
        decision: { enum: [advance, deny], default: advance }
        notification_required: { type: boolean }
    LegalRoleCommand:
      type: object
      additionalProperties: false
      required: [processing_activity_id, legal_role, party_org, accountable_person]
      properties:
        processing_activity_id: { type: string, format: uuid }
        legal_role: { enum: [controller, joint_controller, processor, sub_processor] }
        party_org: { type: string, format: uuid }
        accountable_person: { type: string, format: uuid }
        parent_assignment_id: { type: string, format: uuid, description: Required for sub_processor and forbidden otherwise }
    VersionedReasonCommand:
      type: object
      additionalProperties: false
      required: [expected_version, reason]
      properties:
        expected_version: { type: integer, minimum: 1 }
        reason: { type: string, minLength: 10, maxLength: 4096 }
    DisclosurePurposeCommand:
      type: object
      additionalProperties: false
      required: [controller_org, processing_purpose, legal_basis, data_categories, retention_policy]
      properties:
        controller_org: { type: string, format: uuid }
        processor_org: { type: string, format: uuid }
        processing_purpose: { $ref: '#/components/schemas/Code' }
        legal_basis: { $ref: '#/components/schemas/Code' }
        data_categories: { type: string, minLength: 1, maxLength: 8192 }
        retention_policy: { type: string, format: uuid }
    AssessmentCommand:
      type: object
      additionalProperties: false
      required: [processing_activity_id, risk_description, threat_categories, mitigations, owner_id, approval_state]
      properties:
        processing_activity_id: { type: string, format: uuid }
        risk_description: { type: string, minLength: 1, maxLength: 8192 }
        threat_categories: { type: string, minLength: 1, maxLength: 8192 }
        mitigations: { type: string, minLength: 1, maxLength: 8192 }
        owner_id: { type: string, format: uuid }
        approval_state: { enum: [draft, submitted] }
    AssessmentDecisionCommand:
      type: object
      additionalProperties: false
      required: [expected_version, decision, evidence_ref, reason]
      properties:
        expected_version: { type: integer, minimum: 1 }
        decision: { enum: [submitted, approved, rejected] }
        risk_rating: { enum: [low, medium, high], description: Required to approve }
        evidence_ref: { type: string, format: uuid }
        reason: { type: string, minLength: 10, maxLength: 4096 }
    TransferReviewCommand:
      type: object
      additionalProperties: false
      required: [origin_jurisdiction, destination_jurisdiction, data_categories, legal_authority_ref, safeguard_ref, processing_activity_id]
      properties:
        origin_jurisdiction: { type: string, format: uuid }
        destination_jurisdiction: { type: string, format: uuid, description: Must differ from origin_jurisdiction }
        data_categories: { type: string, minLength: 1, maxLength: 8192 }
        legal_authority_ref: { type: string, format: uuid }
        safeguard_ref: { type: string, format: uuid }
        processing_activity_id: { type: string, format: uuid }
        volume_class: { $ref: '#/components/schemas/Code' }
    PrivacyNoticeCommand:
      type: object
      additionalProperties: false
      required: [notice_version, language, effective_at, review_evidence_ref, publication_channel]
      properties:
        notice_version: { type: string, minLength: 1, maxLength: 512 }
        language: { type: string, pattern: '^[a-z]{2}(-[A-Z]{2})?$' }
        effective_at: { type: string, pattern: '^\d{4}-\d{2}-\d{2}$' }
        review_evidence_ref: { type: string, format: uuid }
        publication_channel: { $ref: '#/components/schemas/Code' }
    IncidentCommand:
      type: object
      additionalProperties: false
      required: [summary, evidence_ref]
      properties:
        processing_activity_id: { type: string, format: uuid }
        summary: { type: string, minLength: 10, maxLength: 4096 }
        evidence_ref: { type: string, format: uuid }
    ExportCommand:
      type: object
      additionalProperties: false
      required: [format]
      properties:
        format: { enum: [csv, pdf] }
        filters: { type: object, additionalProperties: { type: string, maxLength: 128 } }
    DispatchCommand:
      type: object
      additionalProperties: false
      properties:
        limit: { type: integer, minimum: 1, maximum: 500, default: 100 }
