openapi: "3.0.3"
info:
  title: "Sessions and tokens API"
  version: "1.0.0"
  description: "A session is valid only if both the account and the token it was opened with still exist. The token_hash column stores a hash, never the token itself, so a seed written with a plaintext token is not a valid fixture. expires_at is a timestamp, and a generator that emits it as a formatted string fails the timestamp comparison in Postgres. The revoked flag is an integer constrained to zero or one because three different legacy services wrote it."
paths: {}
x-domain-id: "sessions"
x-dialect: "postgres"
components:
  schemas:
    accounts:
      type: "object"
      x-primary-key: "id"
      required: ["id", "email", "created_at"]
      properties:
        id:
          type: "string"
          format: "uuid"
        email:
          type: "string"
          format: "email"
          x-unique: true
        created_at:
          type: "string"
          format: "date-time"
    api_tokens:
      type: "object"
      x-primary-key: "id"
      required: ["id", "account_id", "token_hash", "scopes", "expires_at"]
      properties:
        id:
          type: "string"
          format: "uuid"
        account_id:
          $ref: "#/components/schemas/accounts"
        token_hash:
          type: "string"
          x-unique: true
        scopes:
          type: "string"
        expires_at:
          type: "string"
          format: "date-time"
    sessions:
      type: "object"
      x-primary-key: "id"
      required: ["id", "account_id", "token_id", "ip", "started_at", "revoked"]
      properties:
        id:
          type: "string"
          format: "uuid"
        account_id:
          $ref: "#/components/schemas/accounts"
        token_id:
          $ref: "#/components/schemas/api_tokens"
        ip:
          type: "string"
        started_at:
          type: "string"
          format: "date-time"
        revoked:
          type: "integer"
          minimum: 0
          maximum: 1
