openapi: 3.1.0
info:
  title: HomeVault API
  version: "1"
  summary: REST API of HomeVault, a self-hosted home inventory manager.
  description: |
    Machine-readable companion to [the API reference](https://jnanadarshan.github.io/homevault/API/), which has the full prose
    reference, edge cases and recipes.

    **Two entry points.** `/api/proxy` is used by the web app: open while login
    is off, and needing a session cookie once it is on. `/api/external`
    requires an API key and exposes the same data operations; operations
    marked "web app only" are not available there.

    Errors are returned as `{"message": "..."}`.

    **Segment scoping:** `GET /items`, `/containers`, `/stats`, `/search` and
    `/search/suggest` return only *General* (non-segmented) data by default.
    Pass `segment_id` to scope to one segment, or `include_all=true` for
    everything.
  license:
    name: AGPL-3.0-only
    identifier: AGPL-3.0-only
servers:
  - url: http://localhost:5959/api/external
    description: For external apps; requires an API key
  - url: http://localhost:5959/api/proxy
    description: Used by the web app (Docker default port 5959); session cookie once login is on
  - url: http://localhost:59234/api/v1
    description: Backend directly (inside the container or in development)
security:
  - bearerAuth: []
  - apiKeyHeader: []
  - {}

tags:
  - name: Health & dashboard
  - name: Items
  - name: Categories
  - name: Containers
  - name: Segments
  - name: Floors
  - name: Tags
  - name: Search
  - name: Images
  - name: Backups
  - name: Sync
  - name: Master data
  - name: Test data
  - name: API keys
  - name: Documents & alerts
  - name: Login & users
  - name: History
  - name: Audits
  - name: Updates

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
    apiKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key

  parameters:
    Id:
      name: id
      in: path
      required: true
      schema: { type: integer, format: int64, minimum: 1 }
    SegmentId:
      name: segment_id
      in: query
      description: Only data whose effective segment is this ID.
      schema: { type: integer, format: int64 }
    IncludeAll:
      name: include_all
      in: query
      description: "`true` = General plus every segment (overrides `segment_id`)."
      schema: { type: boolean }
    EntityType:
      name: entity_type
      in: path
      required: true
      schema: { type: string, enum: [item, container] }
    EntityId:
      name: entity_id
      in: path
      required: true
      schema: { type: integer, format: int64 }
    BackupFilename:
      name: filename
      in: path
      required: true
      schema: { type: string, pattern: '^[^/]+\.zip$' }
      example: homevault-data-20260304-020000.zip

  responses:
    NoContent:
      description: Success, no body.
    Error:
      description: Error
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    Status:
      description: Status message
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Status' }

  schemas:
    S3Settings:
      type: object
      properties:
        enabled: { type: boolean }
        endpoint: { type: string, description: Empty means AWS S3 }
        region: { type: string }
        bucket: { type: string }
        prefix: { type: string }
        access_key: { type: string }
        secret_key: { type: string, writeOnly: true }
        secret_key_set: { type: boolean, readOnly: true }
        clear_secret_key: { type: boolean, writeOnly: true }
        last_attempt_at: { type: [string, 'null'], readOnly: true }
        last_success_at: { type: [string, 'null'], readOnly: true }
        last_error: { type: string, readOnly: true }
        syncing: { type: boolean, readOnly: true }
    Health:
      type: object
      properties:
        status: { type: string, enum: [ok, degraded, error] }
        service: { type: string, const: homevault }
        database: { type: object }
        disk: { type: object }
        memory: { type: object }
    Error:
      type: object
      properties:
        message: { type: string }
      required: [message]
    Status:
      type: object
      properties:
        status: { type: string }
    Breadcrumb:
      type: object
      properties:
        id: { type: integer, format: int64 }
        name: { type: string }
        type: { type: string }
    Tag:
      type: object
      properties:
        id: { type: integer, format: int64, readOnly: true }
        name: { type: string }
        color: { type: string, example: '#6366f1' }
      required: [name]
    TagRef:
      type: object
      description: Tag reference used when writing items. Matched by name, created if missing.
      properties:
        name: { type: string }
        color: { type: string }
      required: [name]
    Image:
      type: object
      properties:
        id: { type: integer, format: int64 }
        entity_type: { type: string, enum: [item, container] }
        entity_id: { type: integer, format: int64 }
        filename:
          type: string
          description: Path relative to the images root. Display with `/api/proxy/images/{filename}?size=150|300|600`.
          example: items/42/5b1c0d7e-8f1a-4c4e-9a43-6a1d2c0b51e3.webp
        original_name: { type: string }
        source_url: { type: string, format: uri }
        is_primary: { type: boolean }
        created_at: { type: string, format: date-time }
    ItemWrite:
      type: object
      properties:
        name: { type: string }
        description: { type: [string, 'null'] }
        container_id: { type: [integer, 'null'], format: int64 }
        quantity: { type: number, default: 1 }
        quantity_unit: { type: string, default: pcs }
        quantity_min: { type: [number, 'null'] }
        price: { type: [number, 'null'] }
        currency: { type: string, default: INR }
        purchase_date: { type: [string, 'null'], example: '2025-11-02' }
        expiry_date: { type: [string, 'null'], example: '2027-01-31' }
        warranty_expiry: { type: [string, 'null'] }
        product_url: { type: [string, 'null'] }
        barcode: { type: [string, 'null'] }
        sku: { type: [string, 'null'] }
        serial_number: { type: [string, 'null'] }
        category: { type: [string, 'null'] }
        sub_category: { type: [string, 'null'] }
        notes: { type: [string, 'null'] }
        icon: { type: [string, 'null'] }
        tags:
          type: [array, 'null']
          items: { $ref: '#/components/schemas/TagRef' }
    Item:
      allOf:
        - $ref: '#/components/schemas/ItemWrite'
        - type: object
          properties:
            missing_since: { type: string, description: Set while an audit could not find it }
            id: { type: integer, format: int64 }
            archived: { type: boolean }
            created_at: { type: string, format: date-time }
            updated_at: { type: string, format: date-time }
            container_name: { type: string }
            container_breadcrumb:
              type: array
              items: { $ref: '#/components/schemas/Breadcrumb' }
            tags:
              type: array
              items: { $ref: '#/components/schemas/Tag' }
            images:
              type: array
              items: { $ref: '#/components/schemas/Image' }
    ItemPage:
      type: object
      properties:
        data:
          type: array
          items: { $ref: '#/components/schemas/Item' }
        total: { type: integer }
        page: { type: integer }
        per_page: { type: integer }
        total_pages: { type: integer }
    ItemMovement:
      type: object
      properties:
        id: { type: integer, format: int64 }
        item_id: { type: integer, format: int64 }
        from_container_id: { type: integer, format: int64 }
        to_container_id: { type: integer, format: int64 }
        from_container_name: { type: string }
        to_container_name: { type: string }
        quantity_moved: { type: number }
        moved_at: { type: string, format: date-time }
        notes: { type: string }
    MoveRequest:
      type: object
      properties:
        to_container_id: { type: integer, format: int64 }
        quantity: { type: number, description: Informational only; the whole item moves. }
        notes: { type: string }
      required: [to_container_id]
    ContainerWrite:
      type: object
      properties:
        name: { type: string, description: 'Required except for boxes (defaults to code) and shelves (name or code).' }
        type: { type: string, default: room, examples: [room, shelf, box] }
        description: { type: string }
        parent_id: { type: integer, format: int64 }
        floor_id: { type: integer, format: int64 }
        segment_id: { type: integer, format: int64, description: '0 = General (no segment).' }
        code: { type: string, description: Unique. Required for boxes. }
        map_x: { type: number }
        map_y: { type: number }
        color: { type: string, default: '#6366f1' }
        notes: { type: string }
        icon: { type: string }
    ContainerPatch:
      type: object
      properties:
        name: { type: string }
        type: { type: string }
        color: { type: string }
        description: { type: [string, 'null'] }
        notes: { type: [string, 'null'] }
        code: { type: [string, 'null'] }
        icon: { type: [string, 'null'] }
        parent_id: { type: [integer, 'null'] }
        floor_id: { type: [integer, 'null'] }
        segment_id: { type: [integer, 'null'] }
        map_x: { type: [number, 'null'] }
        map_y: { type: [number, 'null'] }
    Container:
      allOf:
        - $ref: '#/components/schemas/ContainerWrite'
        - type: object
          properties:
            missing_since: { type: string, description: Set while an audit could not find it }
            id: { type: integer, format: int64 }
            archived: { type: boolean }
            created_at: { type: string, format: date-time }
            updated_at: { type: string, format: date-time }
            item_count: { type: integer }
            child_count: { type: integer }
            floor_name: { type: string }
            parent_name: { type: string }
            segment_name: { type: string }
            children:
              type: array
              items: { $ref: '#/components/schemas/Container' }
            items:
              type: array
              items: { $ref: '#/components/schemas/Item' }
            breadcrumb:
              type: array
              items: { $ref: '#/components/schemas/Breadcrumb' }
    Segment:
      type: object
      properties:
        id: { type: integer, format: int64, readOnly: true }
        name: { type: string }
        icon: { type: string, default: Warehouse }
        color: { type: string, default: '#6366f1' }
        description: { type: [string, 'null'] }
        created_at: { type: string, format: date-time, readOnly: true }
        container_count: { type: integer, readOnly: true }
        item_count: { type: integer, readOnly: true }
      required: [name]
    Floor:
      type: object
      properties:
        id: { type: integer, format: int64, readOnly: true }
        name: { type: string }
        level: { type: integer }
        map_image: { type: string, readOnly: true, example: maps/floors/floor_1_1771698564.png }
        created_at: { type: string, format: date-time, readOnly: true }
      required: [name]
    CategoryMeta:
      type: object
      properties:
        name: { type: string }
        icon: { type: [string, 'null'] }
        description: { type: [string, 'null'] }
        sort_order: { type: integer }
        created_at: { type: string, readOnly: true }
        updated_at: { type: string, readOnly: true }
      required: [name]
    Stats:
      type: object
      properties:
        total_items: { type: integer }
        total_containers: { type: integer }
        total_value: { type: number }
        expiring_soon: { type: integer }
        low_stock: { type: integer }
        total_images: { type: integer }
        total_floors: { type: integer }
    SearchResult:
      type: object
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/Item' }
        containers:
          type: array
          items: { $ref: '#/components/schemas/Container' }
    Suggestion:
      type: object
      properties:
        id: { type: integer, format: int64 }
        name: { type: string }
        subtitle: { type: string }
    SuggestResult:
      type: object
      properties:
        items:
          type: array
          items: { $ref: '#/components/schemas/Suggestion' }
        containers:
          type: array
          items: { $ref: '#/components/schemas/Suggestion' }
    BackupInfo:
      type: object
      properties:
        filename: { type: string }
        size: { type: integer, format: int64 }
        created_at: { type: string, format: date-time }
        kind: { type: string, enum: [data, images, full] }
    BackupRunResult:
      type: object
      properties:
        data_file: { type: string }
        images_file: { type: string }
        skipped:
          type: array
          items: { type: string, enum: [data, images] }
    BackupSettings:
      type: object
      properties:
        schedule_enabled: { type: boolean }
        backup_mode: { type: string, enum: [scheduled, onchange] }
        schedule_interval: { type: string, enum: [hourly, daily, weekly, monthly] }
        schedule_time: { type: string, pattern: '^\d{2}:\d{2}$', example: '02:00' }
        network_path: { type: string }
        nfs_username: { type: string }
        nfs_password: { type: string, writeOnly: true, description: 'Empty or omitted keeps the saved password, unless external_ip changes.' }
        nfs_password_set: { type: boolean, readOnly: true }
        clear_nfs_password: { type: boolean, writeOnly: true }
        external_ip: { type: string }
        mount_type: { type: string, enum: [local, nfs, smb] }
        max_backups: { type: integer, minimum: 1, maximum: 100 }
        copy_to_nas_on_schedule: { type: boolean }
        last_backup_at: { type: [string, 'null'], readOnly: true }
        last_images_backup_at: { type: [string, 'null'], readOnly: true }
        last_schedule_check_at: { type: [string, 'null'], readOnly: true }
        last_data_hash: { type: string, readOnly: true }
        last_images_hash: { type: string, readOnly: true }
    ConnectionTestRequest:
      type: object
      properties:
        external_ip: { type: string }
        network_path: { type: string }
        mount_type: { type: string, enum: [local, nfs, smb] }
        nfs_username: { type: string }
        nfs_password: { type: string }
    ConnectionTestResult:
      type: object
      properties:
        ip_status: { $ref: '#/components/schemas/StepStatus' }
        ip_message: { type: string }
        path_status: { $ref: '#/components/schemas/StepStatus' }
        path_message: { type: string }
        transfer_status: { $ref: '#/components/schemas/StepStatus' }
        transfer_message: { type: string }
    StepStatus:
      type: string
      enum: [success, warning, error, none]
    SyncOperation:
      type: object
      properties:
        op_id: { type: string, minLength: 1, maxLength: 128 }
        entity_type: { type: string, enum: [item, container, floor, segment, tag] }
        entity_id: { type: integer, format: int64, description: 0 for CREATE }
        operation: { type: string, enum: [CREATE, UPDATE, DELETE] }
        payload: { type: object, description: Full entity using REST field names. }
        client_updated_at: { type: integer, format: int64, description: Milliseconds since epoch (LWW clock). }
      required: [op_id, entity_type, operation, client_updated_at]
    SyncRequest:
      type: object
      properties:
        client_id: { type: string, pattern: '^[A-Za-z0-9_-]{1,64}$' }
        operations:
          type: array
          maxItems: 500
          items: { $ref: '#/components/schemas/SyncOperation' }
      required: [client_id, operations]
    SyncResponse:
      type: object
      properties:
        applied:
          type: array
          items: { type: string }
        rejected:
          type: array
          items:
            type: object
            properties:
              op_id: { type: string }
              reason: { type: string }
        created:
          type: array
          items:
            type: object
            properties:
              op_id: { type: string }
              entity_id: { type: integer, format: int64 }
        server_updates: {}
    Bootstrap:
      type: object
      properties:
        items: { type: array, items: { type: object } }
        containers: { type: array, items: { type: object } }
        floors: { type: array, items: { type: object } }
        segments: { type: array, items: { type: object } }
        tags: { type: array, items: { type: object } }
        synced_at: { type: integer, format: int64 }
    ApiKey:
      type: object
      properties:
        id: { type: integer, format: int64 }
        name: { type: string }
        prefix: { type: string }
        scope: { type: string, enum: [read, write] }
        created_at: { type: string, format: date-time }
        expires_at: { type: string, format: date-time }
        last_used_at: { type: string, format: date-time }
    TableData:
      type: object
      properties:
        columns:
          type: array
          items:
            type: object
            properties:
              cid: { type: integer }
              name: { type: string }
              type: { type: string }
              notnull: { type: boolean }
              dflt_value: { type: [string, 'null'] }
              pk: { type: integer }
        rows:
          type: array
          items: { type: object, additionalProperties: true }

paths:
  /stocktake/lookup:
    get:
      tags: [Audits]
      summary: Items whose barcode, SKU or serial number equals a code
      parameters:
        - { name: code, in: query, required: true, schema: { type: string } }
      responses:
        '200': { description: Matching items }
  /stocktake/missing:
    get:
      tags: [Audits]
      summary: Items and containers marked missing
      responses:
        '200': { description: "Object with items and containers" }
  /stocktake/mark:
    post:
      tags: [Audits]
      summary: Mark items and containers missing or found
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [status]
              properties:
                status: { type: string, enum: [missing, found] }
                item_ids: { type: array, items: { type: integer } }
                container_ids: { type: array, items: { type: integer } }
                move_to: { type: integer, description: Where they turned up, when found }
      responses:
        '200': { description: Changed }
        '400': { $ref: '#/components/responses/Error' }
  /updates:
    get:
      tags: [Updates]
      summary: Result of the last check for a newer release (admin)
      responses:
        "200": { description: Update status }
    put:
      tags: [Updates]
      summary: Turn update checks on or off (admin)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [enabled]
              properties:
                enabled: { type: boolean }
      responses:
        "200": { description: Update status }
        "409": { description: Turned off by UPDATE_CHECK }
  /updates/check:
    post:
      tags: [Updates]
      summary: Check for a newer release now (admin)
      responses:
        "200": { description: Update status }
        "409": { description: Update checks are off }
  /health:
    get:
      tags: [Health & dashboard]
      summary: Health of the database, data volume and backend
      operationId: health
      responses:
        '200':
          description: Serving, possibly with little disk space left
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Health' }
        '503':
          description: The database does not answer
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Health' }
  /stats:
    get:
      tags: [Health & dashboard]
      summary: Dashboard counters
      operationId: getStats
      parameters:
        - $ref: '#/components/parameters/SegmentId'
        - $ref: '#/components/parameters/IncludeAll'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Stats' }
  /recent:
    get:
      tags: [Health & dashboard]
      summary: 10 newest items (all segments)
      operationId: getRecentItems
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Item' } }
  /expiring:
    get:
      tags: [Health & dashboard]
      summary: Items expiring within 30 days or already expired (max 20)
      operationId: getExpiringItems
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Item' } }
  /low-stock:
    get:
      tags: [Health & dashboard]
      summary: Items below their minimum quantity (max 20)
      operationId: getLowStockItems
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Item' } }

  /items:
    get:
      tags: [Items]
      summary: List items (paginated)
      operationId: listItems
      parameters:
        - { name: page, in: query, schema: { type: integer, minimum: 1, default: 1 } }
        - { name: per_page, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 20 } }
        - { name: q, in: query, description: FTS5 prefix search, schema: { type: string } }
        - { name: container_id, in: query, description: Includes descendant containers, schema: { type: integer } }
        - { name: category, in: query, schema: { type: string } }
        - { name: sub_category, in: query, schema: { type: string } }
        - { name: sort, in: query, schema: { type: string, enum: [name, created_at, updated_at, quantity, price, category, location], default: created_at } }
        - { name: order, in: query, schema: { type: string, enum: [asc, desc], default: desc } }
        - $ref: '#/components/parameters/SegmentId'
        - $ref: '#/components/parameters/IncludeAll'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ItemPage' }
    post:
      tags: [Items]
      summary: Create item
      operationId: createItem
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/ItemWrite'
                - required: [name]
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Item' }
        '400': { $ref: '#/components/responses/Error' }
  /backups/s3:
    get:
      tags: [Backups]
      summary: S3 settings and sync status
      operationId: getS3Settings
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/S3Settings' }
    put:
      tags: [Backups]
      summary: Save S3 settings
      operationId: updateS3Settings
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/S3Settings' }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/S3Settings' }
        '400': { $ref: '#/components/responses/Error' }
  /backups/s3/test:
    post:
      tags: [Backups]
      summary: Check an S3 destination without saving it
      operationId: testS3Settings
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/S3Settings' }
      responses:
        '200': { description: The bucket can be listed, written and deleted from }
        '400': { $ref: '#/components/responses/Error' }
        '502': { $ref: '#/components/responses/Error' }
  /backups/s3/sync:
    post:
      tags: [Backups]
      summary: Start uploading backups to S3
      operationId: syncS3
      responses:
        '202': { description: Started }
        '400': { $ref: '#/components/responses/Error' }
  /items/bulk:
    post:
      tags: [Items]
      summary: Apply one action to many items atomically
      operationId: bulkItems
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [ids, action]
              properties:
                ids: { type: array, minItems: 1, maxItems: 500, items: { type: integer } }
                action: { type: string, enum: [move, delete, restore, add_tags, remove_tags, set_category] }
                container_id: { type: [integer, 'null'], description: Destination for move }
                tags: { type: array, items: { type: string } }
                category: { type: string }
                sub_category: { type: string }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  updated: { type: integer }
        '400': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
  /items/trash:
    get:
      tags: [Items]
      summary: Archived items, most recently archived first
      operationId: listArchivedItems
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Item' } }
  /items/{id}:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    get:
      tags: [Items]
      summary: Get item with tags, all images and location breadcrumb
      operationId: getItem
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Item' }
        '404': { $ref: '#/components/responses/Error' }
    put:
      tags: [Items]
      summary: Partially update item
      description: Only keys present in the body change. `null`/`""` clears a field. `tags` replaces the tag set.
      operationId: updateItem
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ItemWrite' }
      responses:
        '200':
          description: Updated item (without tags/images)
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Item' }
        '404': { $ref: '#/components/responses/Error' }
    delete:
      tags: [Items]
      summary: Archive (soft-delete) item
      operationId: deleteItem
      responses:
        '204': { $ref: '#/components/responses/NoContent' }
  /items/{id}/move:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    post:
      tags: [Items]
      summary: Move item to another container (recorded in history)
      operationId: moveItem
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/MoveRequest' }
      responses:
        '200': { $ref: '#/components/responses/Status' }
  /items/{id}/history:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    get:
      tags: [Items]
      summary: Movement history (newest first)
      operationId: getItemHistory
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/ItemMovement' } }

  /categories:
    get:
      tags: [Categories]
      summary: Distinct categories
      operationId: listCategories
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { type: string } }
  /sub-categories:
    get:
      tags: [Categories]
      summary: Distinct sub-categories
      operationId: listSubCategories
      parameters:
        - { name: category, in: query, schema: { type: string } }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { type: string } }
  /categories/rename:
    put:
      tags: [Categories]
      summary: Rename a category or sub-category on all items
      operationId: renameCategory
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                old_name: { type: string }
                new_name: { type: string }
                is_sub: { type: boolean }
                category: { type: string, description: Parent category (sub-category only) }
              required: [old_name, new_name]
      responses:
        '200': { $ref: '#/components/responses/Status' }
        '400': { $ref: '#/components/responses/Error' }
  /categories/merge:
    post:
      tags: [Categories]
      summary: Merge one category or sub-category into another
      operationId: mergeCategory
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                from: { type: string }
                to: { type: string }
                is_sub: { type: boolean }
                category: { type: string }
              required: [from, to]
      responses:
        '200': { $ref: '#/components/responses/Status' }
        '400': { $ref: '#/components/responses/Error' }
  /categories/meta:
    get:
      tags: [Categories]
      summary: List category display metadata
      operationId: listCategoryMeta
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/CategoryMeta' } }
    put:
      tags: [Categories]
      summary: Create or replace category metadata
      operationId: upsertCategoryMeta
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/CategoryMeta' }
      responses:
        '200': { $ref: '#/components/responses/Status' }
  /categories/meta/{name}:
    delete:
      tags: [Categories]
      summary: Delete category metadata (items untouched)
      operationId: deleteCategoryMeta
      parameters:
        - { name: name, in: path, required: true, schema: { type: string } }
      responses:
        '204': { $ref: '#/components/responses/NoContent' }

  /containers:
    get:
      tags: [Containers]
      summary: Container tree (default) or flat list
      operationId: listContainers
      parameters:
        - { name: flat, in: query, schema: { type: boolean, default: false } }
        - { name: parent_id, in: query, description: Flat mode only, schema: { type: integer } }
        - $ref: '#/components/parameters/SegmentId'
        - $ref: '#/components/parameters/IncludeAll'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Container' } }
    post:
      tags: [Containers]
      summary: Create container
      operationId: createContainer
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ContainerWrite' }
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Container' }
        '400': { $ref: '#/components/responses/Error' }
        '500': { $ref: '#/components/responses/Error' }
  /containers/{id}:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    get:
      tags: [Containers]
      summary: Container with children, direct items and breadcrumb
      operationId: getContainer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Container' }
        '404': { $ref: '#/components/responses/Error' }
    put:
      tags: [Containers]
      summary: Partially update container (omitted fields are kept; null or "" clears)
      operationId: updateContainer
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ContainerPatch' }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Container' }
        '400': { $ref: '#/components/responses/Error' }
        '404': { $ref: '#/components/responses/Error' }
    delete:
      tags: [Containers]
      summary: Archive container
      operationId: deleteContainer
      responses:
        '204': { $ref: '#/components/responses/NoContent' }
        '409':
          description: Container still has child containers
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Error' }
  /containers/{id}/items:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    get:
      tags: [Containers]
      summary: Items in a container
      operationId: listContainerItems
      parameters:
        - { name: recursive, in: query, schema: { type: boolean, default: false } }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Item' } }

  /segments:
    get:
      tags: [Segments]
      summary: List segments with counts
      operationId: listSegments
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Segment' } }
    post:
      tags: [Segments]
      summary: Create segment
      operationId: createSegment
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Segment' }
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Segment' }
        '400': { $ref: '#/components/responses/Error' }
  /segments/{id}:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    get:
      tags: [Segments]
      summary: Get segment
      operationId: getSegment
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Segment' }
        '404': { $ref: '#/components/responses/Error' }
    put:
      tags: [Segments]
      summary: Partially update segment
      operationId: updateSegment
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Segment' }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Segment' }
    delete:
      tags: [Segments]
      summary: Delete segment (its containers move to General)
      operationId: deleteSegment
      responses:
        '204': { $ref: '#/components/responses/NoContent' }

  /floors:
    get:
      tags: [Floors]
      summary: List floors (by level)
      operationId: listFloors
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Floor' } }
    post:
      tags: [Floors]
      summary: Create floor
      operationId: createFloor
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Floor' }
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Floor' }
  /floors/{id}:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    get:
      tags: [Floors]
      summary: Get floor
      operationId: getFloor
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Floor' }
        '404': { $ref: '#/components/responses/Error' }
    put:
      tags: [Floors]
      summary: Replace floor name and level
      operationId: updateFloor
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Floor' }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Floor' }
    delete:
      tags: [Floors]
      summary: Delete floor (409 while non-archived containers are on it)
      operationId: deleteFloor
      responses:
        '204': { $ref: '#/components/responses/NoContent' }
        '409': { $ref: '#/components/responses/Error' }
  /floors/{id}/map:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    post:
      tags: [Floors]
      summary: Upload floor-plan image (max 10 MB)
      operationId: uploadFloorMap
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                image: { type: string, format: binary }
              required: [image]
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  map_image: { type: string }
        '400': { $ref: '#/components/responses/Error' }
    delete:
      tags: [Floors]
      summary: Remove the floor plan and its pins
      operationId: removeFloorMap
      responses:
        '204': { description: Removed }
  /floors/{id}/containers:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    get:
      tags: [Floors]
      summary: Containers on a floor
      operationId: listFloorContainers
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Container' } }

  /tags:
    get:
      tags: [Tags]
      summary: List tags
      operationId: listTags
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Tag' } }
    post:
      tags: [Tags]
      summary: Create tag
      operationId: createTag
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/Tag' }
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Tag' }
        '409': { $ref: '#/components/responses/Error' }
  /tags/{id}:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    delete:
      tags: [Tags]
      summary: Delete tag (removed from all items)
      operationId: deleteTag
      responses:
        '204': { $ref: '#/components/responses/NoContent' }

  /search:
    get:
      tags: [Search]
      summary: Search items and containers (max 30 each)
      operationId: search
      parameters:
        - { name: q, in: query, required: true, schema: { type: string } }
        - $ref: '#/components/parameters/SegmentId'
        - $ref: '#/components/parameters/IncludeAll'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SearchResult' }
  /search/suggest:
    get:
      tags: [Search]
      summary: Typeahead suggestions (min 2 chars, max 6 each)
      operationId: suggest
      parameters:
        - { name: q, in: query, required: true, schema: { type: string, minLength: 2 } }
        - $ref: '#/components/parameters/SegmentId'
        - $ref: '#/components/parameters/IncludeAll'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SuggestResult' }

  /images/{entity_type}/{entity_id}:
    parameters:
      - $ref: '#/components/parameters/EntityType'
      - $ref: '#/components/parameters/EntityId'
    get:
      tags: [Images]
      summary: List images of an item or container
      operationId: listImages
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Image' } }
    post:
      tags: [Images]
      summary: Upload image (JPEG, PNG, WebP, GIF or HEIC, max 20 MB; converted to WebP, 800 px)
      operationId: uploadImage
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                image: { type: string, format: binary }
              required: [image]
            encoding:
              image:
                contentType: image/jpeg, image/png, image/webp, image/gif, image/heic, image/heif
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Image' }
        '400': { $ref: '#/components/responses/Error' }
  /images/{entity_type}/{entity_id}/from-url:
    parameters:
      - $ref: '#/components/parameters/EntityType'
      - $ref: '#/components/parameters/EntityId'
    post:
      tags: [Images]
      summary: Download an image from a public URL
      operationId: uploadImageFromUrl
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                url: { type: string, format: uri }
              required: [url]
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Image' }
        '400': { $ref: '#/components/responses/Error' }
        '502': { $ref: '#/components/responses/Error' }
  /images/{id}:
    parameters: [{ $ref: '#/components/parameters/Id' }]
    delete:
      tags: [Images]
      summary: Delete image and thumbnails
      operationId: deleteImage
      responses:
        '204': { $ref: '#/components/responses/NoContent' }
        '404': { $ref: '#/components/responses/Error' }

  /backups:
    get:
      tags: [Backups]
      summary: List backup files (newest first)
      operationId: listBackups
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/BackupInfo' } }
  /backups/run:
    post:
      tags: [Backups]
      summary: Create a backup now (unchanged artifacts skipped unless force=true)
      operationId: runBackup
      parameters:
        - { name: force, in: query, schema: { type: boolean, default: false } }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/BackupRunResult' }
        '500': { $ref: '#/components/responses/Error' }
  /backups/download/{filename}:
    parameters: [{ $ref: '#/components/parameters/BackupFilename' }]
    get:
      tags: [Backups]
      summary: Download a backup ZIP
      operationId: downloadBackup
      responses:
        '200':
          description: ZIP file
          content:
            application/zip:
              schema: { type: string, format: binary }
        '404': { $ref: '#/components/responses/Error' }
  /backups/{filename}:
    parameters: [{ $ref: '#/components/parameters/BackupFilename' }]
    delete:
      tags: [Backups]
      summary: Delete a backup
      operationId: deleteBackup
      responses:
        '200': { $ref: '#/components/responses/Status' }
        '404': { $ref: '#/components/responses/Error' }
  /backups/{filename}/copy-to-nas:
    parameters: [{ $ref: '#/components/parameters/BackupFilename' }]
    post:
      tags: [Backups]
      summary: Copy a backup to the configured network target
      operationId: copyBackupToNas
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status: { type: string }
                  destination: { type: string }
        '400': { $ref: '#/components/responses/Error' }
        '500': { $ref: '#/components/responses/Error' }
  /backups/restore:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    post:
      tags: [Backups]
      summary: Restore from one or more backup ZIPs (max 512 MB total; restart afterwards)
      operationId: restoreBackup
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                backup:
                  type: array
                  items: { type: string, format: binary }
              required: [backup]
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status: { type: string }
                  database_restored: { type: boolean }
                  images_restored: { type: integer }
                  message: { type: string }
        '400': { $ref: '#/components/responses/Error' }
  /backups/settings:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    get:
      tags: [Backups]
      summary: Get backup settings (the NAS password is never returned)
      operationId: getBackupSettings
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/BackupSettings' }
    put:
      tags: [Backups]
      summary: Partially update backup settings
      operationId: updateBackupSettings
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/BackupSettings' }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/BackupSettings' }
  /backups/test-connection:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    post:
      tags: [Backups]
      summary: Test a NAS target (ping, mount, write/read-back)
      operationId: testBackupConnection
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ConnectionTestRequest' }
      responses:
        '200':
          description: Per-step results (always 200)
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ConnectionTestResult' }

  /sync:
    post:
      tags: [Sync]
      summary: Apply a batch of offline operations (last-writer-wins)
      operationId: sync
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyncRequest' }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SyncResponse' }
        '400': { $ref: '#/components/responses/Error' }
  /sync/bootstrap:
    get:
      tags: [Sync]
      summary: Full snapshot for the offline client
      operationId: syncBootstrap
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Bootstrap' }

  /db/tables:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    get:
      tags: [Master data]
      summary: List editable tables
      operationId: listTables
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { type: string } }
  /db/tables/{name}:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    get:
      tags: [Master data]
      summary: Table schema and first 1000 rows
      operationId: getTable
      parameters:
        - name: name
          in: path
          required: true
          schema: { type: string, enum: [floors, containers, items, tags, item_tags, images, item_movements, segments] }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { $ref: '#/components/schemas/TableData' }
        '403': { $ref: '#/components/responses/Error' }
  /db/tables/{name}/{id}:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    put:
      tags: [Master data]
      summary: Set columns on one row (no validation)
      operationId: updateTableRow
      parameters:
        - name: name
          in: path
          required: true
          schema: { type: string, enum: [floors, containers, items, tags, images, item_movements, segments] }
        - $ref: '#/components/parameters/Id'
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, additionalProperties: true }
            example: { archived: 0 }
      responses:
        '200': { $ref: '#/components/responses/Status' }
        '400': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }

  /seed-data:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    post:
      tags: [Test data]
      summary: Add the demo dataset
      operationId: seedData
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status: { type: string }
                  floors: { type: integer }
                  segments: { type: integer }
                  rooms: { type: integer }
                  shelves: { type: integer }
                  boxes: { type: integer }
                  items: { type: integer }
        '409': { $ref: '#/components/responses/Error' }
    delete:
      tags: [Test data]
      summary: Remove the demo dataset
      operationId: wipeSeedData
      responses:
        '200': { $ref: '#/components/responses/Status' }
  /seed-data/status:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    get:
      tags: [Test data]
      summary: Whether demo data is present
      operationId: seedDataStatus
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  seeded: { type: boolean }
                  items: { type: integer }
                  containers: { type: integer }

  /api-keys:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    get:
      tags: [API keys]
      summary: List API keys (web app only)
      operationId: listApiKeys
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/ApiKey' } }
    post:
      tags: [API keys]
      summary: Create an API key; the key is returned only once (web app only)
      operationId: createApiKey
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, maxLength: 100 }
                scope: { type: string, enum: [read, write], default: read }
                expires_in_days: { type: integer, minimum: 0, maximum: 3650, default: 0 }
              required: [name]
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/ApiKey'
                  - type: object
                    properties:
                      key: { type: string }
        '400': { $ref: '#/components/responses/Error' }
  /api-keys/{id}:
    # web app only
    servers:
      - url: http://localhost:5959/api/proxy
    x-web-app-only: true
    parameters: [{ $ref: '#/components/parameters/Id' }]
    delete:
      tags: [API keys]
      summary: Revoke an API key (web app only)
      operationId: revokeApiKey
      responses:
        '204': { $ref: '#/components/responses/NoContent' }
        '404': { $ref: '#/components/responses/Error' }
  /items/{id}/attachments:
    get:
      tags: ['Documents & alerts']
      summary: List documents of an item
      operationId: listAttachments
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
    post:
      tags: ['Documents & alerts']
      summary: Attach a PDF or picture to an item
      operationId: uploadAttachment
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema: { type: object, required: [file], properties: { file: { type: string, format: binary }, kind: { type: string, enum: [warranty, receipt, manual, other] } } }
      responses:
        '201': { description: Attached }
        default: { $ref: '#/components/responses/Error' }
  /attachments/{id}/file:
    get:
      tags: ['Documents & alerts']
      summary: Download a document
      operationId: downloadAttachment
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      responses:
        '200': { description: The file }
        default: { $ref: '#/components/responses/Error' }
  /attachments/{id}:
    delete:
      tags: ['Documents & alerts']
      summary: Delete a document
      operationId: deleteAttachment
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      responses:
        '204': { description: Deleted }
        default: { $ref: '#/components/responses/Error' }
  /alerts:
    get:
      tags: ['Documents & alerts']
      summary: Warranties and expiry dates coming up
      operationId: listAlerts
      parameters:
        - { name: days, in: query, schema: { type: integer, minimum: 1, maximum: 365, default: 30 } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
  /auth/status:
    get:
      tags: ['Login & users']
      summary: Whether login is on, and who is signed in (web app only)
      operationId: authStatus
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
  /auth/setup:
    post:
      tags: ['Login & users']
      summary: Create the first admin and turn login on (web app only)
      operationId: authSetup
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [username, password], properties: { username: { type: string }, password: { type: string } } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
  /auth/login:
    post:
      tags: ['Login & users']
      summary: Sign in (web app only)
      operationId: login
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [username, password], properties: { username: { type: string }, password: { type: string } } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
  /auth/logout:
    post:
      tags: ['Login & users']
      summary: Sign out (web app only)
      operationId: logout
      responses:
        '204': { description: Signed out }
        default: { $ref: '#/components/responses/Error' }
  /auth/credentials:
    put:
      tags: ['Login & users']
      summary: Change your own username and password (web app only)
      operationId: changeCredentials
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [username, password, current_password], properties: { username: { type: string }, password: { type: string }, current_password: { type: string } } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
  /auth/disable:
    post:
      tags: ['Login & users']
      summary: Turn login off and remove every account (web app only)
      operationId: disableLogin
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [password], properties: { password: { type: string } } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
  /users:
    get:
      tags: ['Login & users']
      summary: List users (web app only)
      operationId: listUsers
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
    post:
      tags: ['Login & users']
      summary: Add a user (web app only)
      operationId: createUser
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [username, password, role], properties: { username: { type: string }, password: { type: string }, role: { type: string, enum: [admin, editor, viewer] } } }
      responses:
        '201': { description: Created }
        default: { $ref: '#/components/responses/Error' }
  /users/{id}:
    put:
      tags: ['Login & users']
      summary: Change a user (web app only)
      operationId: updateUser
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, properties: { username: { type: string }, password: { type: string }, role: { type: string, enum: [admin, editor, viewer] } } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
    delete:
      tags: ['Login & users']
      summary: Delete a user (web app only)
      operationId: deleteUser
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      responses:
        '204': { description: Deleted }
        default: { $ref: '#/components/responses/Error' }
  /audit:
    get:
      tags: [History]
      summary: Change history (web app only)
      operationId: listAudit
      parameters:
        - { name: table, in: query, schema: { type: string } }
        - { name: row_id, in: query, schema: { type: string } }
        - { name: page, in: query, schema: { type: integer } }
        - { name: per_page, in: query, schema: { type: integer, maximum: 100 } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
  /trash:
    get:
      tags: [History]
      summary: Deleted records that can be restored (web app only)
      operationId: listTrash
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
  /trash/restore:
    post:
      tags: [History]
      summary: Restore a deleted record (web app only)
      operationId: restoreTrash
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [kind, id], properties: { kind: { type: string }, id: { type: integer } } }
      responses:
        '200': { description: OK }
        default: { $ref: '#/components/responses/Error' }
