{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/observeinc/json-schema/observeinc-service-account-resource-schema.json",
  "title": "ServiceAccountObject",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/observeinc-service-accounts-api-openapi.yml#/components/schemas/ServiceAccount-Resource",
  "type": "object",
  "required": [
    "id",
    "label",
    "description",
    "createdBy",
    "createdAt",
    "updatedBy",
    "updatedAt",
    "disabled",
    "externalOAuth"
  ],
  "properties": {
    "id": {
      "$ref": "#/$defs/ObjectId"
    },
    "label": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "createdBy": {
      "$ref": "#/$defs/User"
    },
    "createdAt": {
      "$ref": "#/$defs/Time"
    },
    "updatedBy": {
      "$ref": "#/$defs/User"
    },
    "updatedAt": {
      "$ref": "#/$defs/Time"
    },
    "disabled": {
      "type": "boolean",
      "description": "Whether the service account is disabled. Disabling a service account will delete all of its API tokens."
    },
    "apiTokenCount": {
      "type": "integer",
      "format": "int64",
      "description": "Number of API tokens for this service account. Includes recently expired and disabled tokens. Only populated when the expand query parameter is set to true."
    },
    "rbacGroups": {
      "type": "array",
      "description": "RBAC groups this service account belongs to. Only populated when the expand query parameter is set to true.",
      "items": {
        "$ref": "#/$defs/RbacGroupRef"
      }
    },
    "externalOAuth": {
      "description": "The external OAuth binding for this service account, or null if no binding exists.",
      "anyOf": [
        {
          "$ref": "#/$defs/ServiceAccount-ExternalOAuth"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "$defs": {
    "OAuthExternalIntegrationRef": {
      "title": "OAuthExternalIntegrationRef",
      "type": "object",
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/ObjectId"
        }
      }
    },
    "ObjectId": {
      "type": "string",
      "format": "ObjectId"
    },
    "RbacGroupRef": {
      "title": "RbacGroupRef",
      "description": "Reference to an RBAC group, including id, label, and description.",
      "type": "object",
      "required": [
        "id",
        "legacyId",
        "label",
        "description"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/ObjectId"
        },
        "legacyId": {
          "type": "string",
          "description": "Deprecated. For compatibility with legacy APIs.",
          "deprecated": true
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      }
    },
    "ServiceAccount-ExternalOAuth": {
      "title": "ServiceAccountExternalOAuth",
      "type": "object",
      "required": [
        "integration",
        "subject"
      ],
      "properties": {
        "integration": {
          "$ref": "#/$defs/OAuthExternalIntegrationRef"
        },
        "subject": {
          "type": "string",
          "description": "The external identity subject (JWT sub/oid claim) this service account is bound to."
        }
      }
    },
    "Time": {
      "type": "string",
      "format": "RFC3339"
    },
    "User": {
      "title": "User",
      "type": "object",
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "title": "User Identifier",
          "$ref": "#/$defs/ObjectId"
        },
        "label": {
          "title": "User Label",
          "type": "string"
        },
        "timezone": {
          "type": "string"
        },
        "locale": {
          "type": "string"
        }
      }
    }
  }
}