{
  "openapi": "3.0.3",
  "info": {
    "title": "CodeThreat API",
    "version": "1.0.0",
    "description": "Autonomous AppSec Engineering Platform - Comprehensive REST API for security scanning, vulnerability management, and DevSecOps automation. Integrate CodeThreat's powerful security analysis into your CI/CD pipeline, CLI tools, and third-party applications.",
    "contact": {
      "name": "CodeThreat Support",
      "url": "https://codethreat.com/support",
      "email": "support@codethreat.com"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://codethreat.com/terms"
    },
    "termsOfService": "https://codethreat.com/terms"
  },
  "servers": [
    {
      "url": "https://app.codethreat.com/api/v1",
      "description": "Production Server"
    },
    {
      "url": "http://localhost:3000/api/v1",
      "description": "Development Server"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "Organizations",
      "description": "Organization management and configuration"
    },
    {
      "name": "Repositories",
      "description": "Repository management and status tracking"
    },
    {
      "name": "Scans",
      "description": "Security scan execution, monitoring, and results"
    },
    {
      "name": "Violations",
      "description": "Security violation tracking and management"
    },
    {
      "name": "CLI",
      "description": "CLI-specific endpoints for authentication and configuration"
    },
    {
      "name": "System",
      "description": "Health checks and system status"
    }
  ],
  "paths": {
    "/organizations": {
      "get": {
        "tags": ["Organizations"],
        "summary": "List organizations",
        "description": "Get a paginated list of organizations for the authenticated user",
        "operationId": "listOrganizations",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "description": "Page number",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Items per page",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Search query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by status",
            "schema": {
              "type": "string",
              "enum": ["active", "inactive"]
            }
          },
          {
            "name": "sortBy",
            "in": "query",
            "description": "Sort field",
            "schema": {
              "type": "string",
              "enum": ["name", "createdAt", "updatedAt"],
              "default": "updatedAt"
            }
          },
          {
            "name": "sortOrder",
            "in": "query",
            "description": "Sort order",
            "schema": {
              "type": "string",
              "enum": ["asc", "desc"],
              "default": "desc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrganizationListResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitError"
          }
        }
      }
    },
    "/organizations/{id}": {
      "get": {
        "tags": ["Organizations"],
        "summary": "Get organization",
        "description": "Get details of a specific organization",
        "operationId": "getOrganization",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrganizationResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      }
    },
    "/repositories": {
      "get": {
        "tags": ["Repositories"],
        "summary": "List repositories",
        "description": "Get a paginated list of repositories for the authenticated organization",
        "operationId": "listRepositories",
        "parameters": [
          {
            "$ref": "#/components/parameters/PageParam"
          },
          {
            "$ref": "#/components/parameters/LimitParam"
          },
          {
            "name": "search",
            "in": "query",
            "description": "Search repositories by name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "provider",
            "in": "query",
            "description": "Filter by provider",
            "schema": {
              "type": "string",
              "enum": ["github", "gitlab", "bitbucket", "azure_devops"]
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by status",
            "schema": {
              "type": "string",
              "enum": ["active", "inactive", "archived"]
            }
          },
          {
            "name": "sortBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["name", "createdAt", "updatedAt", "lastScanAt"],
              "default": "updatedAt"
            }
          },
          {
            "name": "sortOrder",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["asc", "desc"],
              "default": "desc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepositoryListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/repositories/{id}": {
      "get": {
        "tags": ["Repositories"],
        "summary": "Get repository",
        "description": "Get details of a specific repository",
        "operationId": "getRepository",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Repository ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepositoryResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      }
    },
    "/repositories/{id}/status": {
      "get": {
        "tags": ["Repositories"],
        "summary": "Get repository status",
        "description": "Get repository status including import status, scan information, and capabilities",
        "operationId": "getRepositoryStatus",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Repository ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepositoryStatusResponse"
                }
              }
            }
          }
        }
      }
    },
    "/repositories/search": {
      "get": {
        "tags": ["Repositories"],
        "summary": "Search repositories",
        "description": "Advanced repository search with filtering and sorting",
        "operationId": "searchRepositories",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "required": true,
            "description": "Search query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "provider",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["github", "gitlab", "bitbucket", "azure_devops"]
            }
          },
          {
            "name": "hasScans",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "includeStats",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "$ref": "#/components/parameters/PageParam"
          },
          {
            "$ref": "#/components/parameters/LimitParam"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepositoryListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/scans": {
      "get": {
        "tags": ["Scans"],
        "summary": "List scans",
        "description": "Get a paginated list of security scans",
        "operationId": "listScans",
        "parameters": [
          {
            "$ref": "#/components/parameters/PageParam"
          },
          {
            "$ref": "#/components/parameters/LimitParam"
          },
          {
            "name": "repositoryId",
            "in": "query",
            "description": "Filter by repository",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by status",
            "schema": {
              "type": "string",
              "enum": ["PENDING", "SCANNING", "COMPLETED", "FAILED"]
            }
          },
          {
            "name": "scanType",
            "in": "query",
            "description": "Filter by scan type",
            "schema": {
              "type": "string",
              "enum": ["sast", "sca", "secrets", "iac"]
            }
          },
          {
            "name": "sortBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["startedAt", "completedAt", "status"],
              "default": "startedAt"
            }
          },
          {
            "name": "sortOrder",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["asc", "desc"],
              "default": "desc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanListResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["Scans"],
        "summary": "Trigger scan",
        "description": "Trigger a new security scan for a repository",
        "operationId": "createScan",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateScanRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Scan created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResponse"
                }
              }
            }
          }
        }
      }
    },
    "/scans/{id}": {
      "get": {
        "tags": ["Scans"],
        "summary": "Get scan",
        "description": "Get details of a specific scan",
        "operationId": "getScan",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Scan ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          }
        }
      }
    },
    "/scans/{id}/status": {
      "get": {
        "tags": ["Scans"],
        "summary": "Get detailed scan status",
        "description": "Get detailed scan status with progress information",
        "operationId": "getScanStatusDetailed",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Scan ID",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "includeProgress",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "includeLogs",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanStatusResponse"
                }
              }
            }
          }
        }
      }
    },
    "/scans/{id}/results": {
      "get": {
        "tags": ["Scans"],
        "summary": "Export scan results",
        "description": "Export scan results in various formats (JSON, SARIF, CSV, XML, JUnit)",
        "operationId": "exportScanResults",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Scan ID",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "description": "Export format",
            "schema": {
              "type": "string",
              "enum": ["json", "sarif", "csv", "xml", "junit"],
              "default": "json"
            }
          },
          {
            "name": "severity",
            "in": "query",
            "description": "Filter by severity",
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": ["critical", "high", "medium", "low", "info"]
              }
            }
          },
          {
            "name": "includeFixed",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "includeSuppressed",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              },
              "application/sarif+json": {
                "schema": {
                  "type": "object"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/scans/run": {
      "post": {
        "tags": ["Scans"],
        "summary": "Run scan (sync/async)",
        "description": "Start a scan and optionally wait for completion",
        "operationId": "runScan",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RunScanRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Scan completed (if wait=true)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResponse"
                }
              }
            }
          },
          "202": {
            "description": "Scan started (if wait=false)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResponse"
                }
              }
            }
          }
        }
      }
    },
    "/violations": {
      "get": {
        "tags": ["Violations"],
        "summary": "List violations",
        "description": "Get a paginated list of security violations",
        "operationId": "listViolations",
        "parameters": [
          {
            "$ref": "#/components/parameters/PageParam"
          },
          {
            "$ref": "#/components/parameters/LimitParam"
          },
          {
            "name": "scanId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "repositoryId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "severity",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["critical", "high", "medium", "low", "info"]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["open", "fixed", "ignored", "false_positive"]
            }
          },
          {
            "name": "ruleId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ViolationListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/violations/{id}": {
      "get": {
        "tags": ["Violations"],
        "summary": "Get violation",
        "description": "Get details of a specific violation",
        "operationId": "getViolation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ViolationResponse"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": ["Violations"],
        "summary": "Update violation",
        "description": "Update violation status or add comments",
        "operationId": "updateViolation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateViolationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Violation updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ViolationResponse"
                }
              }
            }
          }
        }
      }
    },
    "/cli/info": {
      "get": {
        "tags": ["CLI"],
        "summary": "Get CLI information",
        "description": "Get CLI-specific information including supported features, versions, and capabilities",
        "operationId": "getCliInfo",
        "security": [],
        "parameters": [
          {
            "name": "includeCapabilities",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "includeVersions",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CliInfoResponse"
                }
              }
            }
          }
        }
      }
    },
    "/cli/auth/validate": {
      "get": {
        "tags": ["CLI"],
        "summary": "Validate CLI authentication",
        "description": "Validate authentication and return user context information",
        "operationId": "validateCliAuth",
        "parameters": [
          {
            "name": "includePermissions",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "includeOrganizations",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "includeUsage",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authentication valid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CliAuthValidationResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": ["System"],
        "summary": "Health check",
        "description": "Check API health and system status",
        "operationId": "healthCheck",
        "security": [],
        "responses": {
          "200": {
            "description": "System healthy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthCheckResponse"
                }
              }
            }
          },
          "503": {
            "description": "System unhealthy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthCheckResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key for authentication. Generate from your organization settings."
      }
    },
    "parameters": {
      "PageParam": {
        "name": "page",
        "in": "query",
        "description": "Page number",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "default": 1
        }
      },
      "LimitParam": {
        "name": "limit",
        "in": "query",
        "description": "Items per page",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 20
        }
      }
    },
    "schemas": {
      "ApiResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "data": {
            "type": "object"
          },
          "pagination": {
            "$ref": "#/components/schemas/Pagination"
          },
          "meta": {
            "$ref": "#/components/schemas/ResponseMeta"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "enum": [false]
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "UNAUTHORIZED",
                  "FORBIDDEN",
                  "INVALID_API_KEY",
                  "EXPIRED_API_KEY",
                  "INSUFFICIENT_SCOPE",
                  "VALIDATION_ERROR",
                  "INVALID_INPUT",
                  "NOT_FOUND",
                  "ALREADY_EXISTS",
                  "CONFLICT",
                  "RATE_LIMIT_EXCEEDED",
                  "INTERNAL_ERROR",
                  "SERVICE_UNAVAILABLE",
                  "TIMEOUT"
                ]
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object"
              }
            }
          },
          "meta": {
            "$ref": "#/components/schemas/ResponseMeta"
          }
        }
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer",
            "minimum": 1
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "totalPages": {
            "type": "integer",
            "minimum": 0
          },
          "hasNext": {
            "type": "boolean"
          },
          "hasPrev": {
            "type": "boolean"
          }
        }
      },
      "ResponseMeta": {
        "type": "object",
        "properties": {
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "string"
          },
          "requestId": {
            "type": "string"
          },
          "organizationId": {
            "type": "string"
          }
        }
      },
      "Organization": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "planType": {
            "type": "string",
            "enum": ["FREE", "PRO"]
          },
          "isPersonal": {
            "type": "boolean"
          },
          "usageBalance": {
            "type": "number"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OrganizationListResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Organization"
                }
              }
            }
          }
        ]
      },
      "OrganizationResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/Organization"
              }
            }
          }
        ]
      },
      "Repository": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "provider": {
            "type": "string",
            "enum": ["github", "gitlab", "bitbucket", "azure_devops"]
          },
          "status": {
            "type": "string",
            "enum": ["active", "inactive", "archived"]
          },
          "description": {
            "type": "string"
          },
          "lastScanAt": {
            "type": "string",
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "RepositoryListResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Repository"
                }
              }
            }
          }
        ]
      },
      "RepositoryResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/Repository"
              }
            }
          }
        ]
      },
      "RepositoryStatusResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string"
                  },
                  "importStatus": {
                    "type": "string"
                  },
                  "lastScan": {
                    "type": "object"
                  },
                  "capabilities": {
                    "type": "object"
                  }
                }
              }
            }
          }
        ]
      },
      "Scan": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "repositoryId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["PENDING", "SCANNING", "COMPLETED", "FAILED"]
          },
          "scanTypes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["sast", "sca", "secrets", "iac"]
            }
          },
          "branch": {
            "type": "string"
          },
          "commit": {
            "type": "string"
          },
          "startedAt": {
            "type": "string",
            "format": "date-time"
          },
          "completedAt": {
            "type": "string",
            "format": "date-time"
          },
          "duration": {
            "type": "integer"
          },
          "violationCount": {
            "type": "object",
            "properties": {
              "critical": {
                "type": "integer"
              },
              "high": {
                "type": "integer"
              },
              "medium": {
                "type": "integer"
              },
              "low": {
                "type": "integer"
              },
              "info": {
                "type": "integer"
              }
            }
          }
        }
      },
      "ScanListResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Scan"
                }
              }
            }
          }
        ]
      },
      "ScanResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/Scan"
              }
            }
          }
        ]
      },
      "ScanStatusResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string"
                  },
                  "progress": {
                    "type": "object"
                  },
                  "logs": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "CreateScanRequest": {
        "type": "object",
        "required": ["repositoryId"],
        "properties": {
          "repositoryId": {
            "type": "string"
          },
          "scanTypes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["sast", "sca", "secrets", "iac", "scan"]
            }
          },
          "branch": {
            "type": "string"
          },
          "commit": {
            "type": "string"
          }
        }
      },
      "RunScanRequest": {
        "type": "object",
        "required": ["repositoryId"],
        "properties": {
          "repositoryId": {
            "type": "string"
          },
          "branch": {
            "type": "string",
            "default": "main"
          },
          "scanTypes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["sast", "sca", "secrets", "iac", "scan"]
            }
          },
          "wait": {
            "type": "boolean",
            "default": false,
            "description": "Wait for scan completion"
          },
          "timeout": {
            "type": "integer",
            "minimum": 60,
            "maximum": 3600,
            "default": 1800,
            "description": "Timeout in seconds (only if wait=true)"
          },
          "pollInterval": {
            "type": "integer",
            "minimum": 5,
            "maximum": 60,
            "default": 10,
            "description": "Poll interval in seconds (only if wait=true)"
          },
          "scanTrigger": {
            "type": "string",
            "enum": ["manual", "ci/cd", "api"],
            "default": "api"
          },
          "pullRequestId": {
            "type": "string"
          },
          "commitSha": {
            "type": "string"
          },
          "metadata": {
            "type": "object"
          }
        }
      },
      "Violation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "scanId": {
            "type": "string"
          },
          "repositoryId": {
            "type": "string"
          },
          "ruleId": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": ["critical", "high", "medium", "low", "info"]
          },
          "status": {
            "type": "string",
            "enum": ["open", "fixed", "ignored", "false_positive"]
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "file": {
            "type": "string"
          },
          "line": {
            "type": "integer"
          },
          "column": {
            "type": "integer"
          },
          "codeSnippet": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ViolationListResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Violation"
                }
              }
            }
          }
        ]
      },
      "ViolationResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/Violation"
              }
            }
          }
        ]
      },
      "UpdateViolationRequest": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": ["open", "fixed", "ignored", "false_positive"]
          },
          "comment": {
            "type": "string"
          },
          "suppressionReason": {
            "type": "string"
          }
        }
      },
      "CliInfoResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "object",
                "properties": {
                  "cli": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "version": {
                        "type": "string"
                      },
                      "supportedPlatforms": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "supportedArchitectures": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "api": {
                    "type": "object",
                    "properties": {
                      "version": {
                        "type": "string"
                      },
                      "baseUrl": {
                        "type": "string"
                      },
                      "endpoints": {
                        "type": "object"
                      }
                    }
                  },
                  "supportedFormats": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "supportedProviders": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "capabilities": {
                    "type": "object"
                  }
                }
              }
            }
          }
        ]
      },
      "CliAuthValidationResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "object",
                "properties": {
                  "valid": {
                    "type": "boolean"
                  },
                  "user": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      }
                    }
                  },
                  "organizations": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Organization"
                    }
                  },
                  "permissions": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "usage": {
                    "type": "object"
                  },
                  "authenticatedAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        ]
      },
      "HealthCheckResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "data": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string",
                "enum": ["healthy", "degraded", "unhealthy"]
              },
              "version": {
                "type": "string"
              },
              "timestamp": {
                "type": "string",
                "format": "date-time"
              },
              "services": {
                "type": "object",
                "properties": {
                  "database": {
                    "type": "string",
                    "enum": ["up", "down"]
                  },
                  "redis": {
                    "type": "string",
                    "enum": ["up", "down"]
                  }
                }
              }
            }
          }
        }
      }
    },
    "responses": {
      "UnauthorizedError": {
        "description": "Authentication required or invalid API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "error": {
                "code": "UNAUTHORIZED",
                "message": "Authentication required. Please provide a valid API key."
              },
              "meta": {
                "timestamp": "2025-01-15T10:30:00Z",
                "version": "v1",
                "requestId": "req_123456"
              }
            }
          }
        }
      },
      "ForbiddenError": {
        "description": "Insufficient permissions",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "error": {
                "code": "FORBIDDEN",
                "message": "You don't have permission to access this resource."
              },
              "meta": {
                "timestamp": "2025-01-15T10:30:00Z",
                "version": "v1",
                "requestId": "req_123456"
              }
            }
          }
        }
      },
      "NotFoundError": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "error": {
                "code": "NOT_FOUND",
                "message": "The requested resource was not found."
              },
              "meta": {
                "timestamp": "2025-01-15T10:30:00Z",
                "version": "v1",
                "requestId": "req_123456"
              }
            }
          }
        }
      },
      "ValidationError": {
        "description": "Validation error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "error": {
                "code": "VALIDATION_ERROR",
                "message": "Invalid request parameters",
                "details": {
                  "url": "Invalid URL format"
                }
              },
              "meta": {
                "timestamp": "2025-01-15T10:30:00Z",
                "version": "v1",
                "requestId": "req_123456"
              }
            }
          }
        }
      },
      "RateLimitError": {
        "description": "Rate limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "error": {
                "code": "RATE_LIMIT_EXCEEDED",
                "message": "Rate limit exceeded. Please try again later.",
                "details": {
                  "retryAfter": 60
                }
              },
              "meta": {
                "timestamp": "2025-01-15T10:30:00Z",
                "version": "v1",
                "requestId": "req_123456"
              }
            }
          }
        }
      }
    }
  },
  "x-tagGroups": [
    {
      "name": "Core Resources",
      "tags": ["Organizations", "Repositories", "Scans", "Violations"]
    },
    {
      "name": "Developer Tools",
      "tags": ["CLI", "System"]
    }
  ]
}
