{
  "openapi": "3.0.3",
  "info": {
    "title": "CasePilot API",
    "description": "AI-powered test case generation for Azure DevOps. Uses a two-pass Worker + Judge pipeline to produce structured, categorized, automation-ready test cases from user story descriptions.",
    "version": "1.0.0",
    "contact": {
      "name": "CasePilot Support",
      "email": "support@iklab.dev"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://api.iklab.dev",
      "description": "Production"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/api/v1/generate": {
      "post": {
        "operationId": "generateTestCases",
        "summary": "Generate test cases",
        "description": "Generate structured test cases from a user story description using the two-pass Worker + Judge AI pipeline. Each generated test case counts against your monthly usage quota.",
        "tags": [
          "Generation"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Test cases generated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerationResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit or usage limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "AI service temporarily unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Get usage and credits",
        "description": "Returns current credit usage for your organization in the current billing period.",
        "tags": [
          "Usage"
        ],
        "responses": {
          "200": {
            "description": "Usage information",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/keys/create": {
      "post": {
        "operationId": "createApiKey",
        "summary": "Create an API key",
        "description": "Create a new API key for your organization. The full key value is returned only once — store it securely.",
        "tags": [
          "API Keys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateKeyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "API key created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateKeyResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/keys/list": {
      "get": {
        "operationId": "listApiKeys",
        "summary": "List API keys",
        "description": "List all active API keys for your organization. Key values are masked — only the last 4 characters are shown.",
        "tags": [
          "API Keys"
        ],
        "responses": {
          "200": {
            "description": "List of API keys",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiKeyInfo"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/keys/revoke": {
      "post": {
        "operationId": "revokeApiKey",
        "summary": "Revoke an API key",
        "description": "Revoke an API key. The key will immediately stop working for all requests.",
        "tags": [
          "API Keys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RevokeKeyRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Key revoked successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Key revoked successfully"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Key not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/enrich-story": {
      "post": {
        "operationId": "enrichStory",
        "summary": "Enrich a User Story (StoryPilot)",
        "description": "Enriches a User Story title into a fully detailed story with description, acceptance criteria, priority, story points, risks, and definition of done. Uses the two-pass Worker + Judge AI pipeline. Consumes 1 CasePilot credit per enrichment.",
        "tags": [
          "StoryPilot"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EnrichStoryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Story enriched successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EnrichStoryResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit or usage limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/coverage-matrix": {
      "post": {
        "operationId": "buildCoverageMatrix",
        "summary": "Cross-story coverage matrix",
        "description": "Build a 4-dimension coverage heatmap across multiple stories. Detects gap clusters, cross-story dependencies, and risk areas. Free — does not consume credits.",
        "tags": [
          "Coverage"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CoverageMatrixRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Coverage matrix result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CoverageMatrixResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/sprint-coverage": {
      "post": {
        "operationId": "analyzeSprintCoverage",
        "summary": "Analyze sprint test coverage",
        "description": "Analyzes all User Stories in a sprint for test coverage gaps and risks. Returns coverage percentage, risk levels, and per-story analysis. Free — does not consume credits.",
        "tags": [
          "Coverage"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SprintCoverageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Coverage analysis result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SprintCoverageResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/v1/test-health": {
      "post": {
        "operationId": "computeTestHealth",
        "summary": "Compute project-level test health score (A-F)",
        "description": "Analyzes test results for a project and computes a health score (0-100) with a letter grade (A-F). Evaluates pass rate, flakiness, duration, and coverage factors. Requires an API key.",
        "tags": [
          "Test Intelligence"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TestHealthRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Test health score computed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestHealthResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/failure-triage": {
      "post": {
        "operationId": "triageFailures",
        "summary": "Group test failures by root cause category",
        "description": "Analyzes test failures and groups them by root cause category (timeout, assertion, connection, permission, resource, flaky, unknown). Provides per-group suggestions and an overall summary. Requires an API key.",
        "tags": [
          "Test Intelligence"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FailureTriageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Failures triaged successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FailureTriageResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/incident-bridge": {
      "post": {
        "operationId": "generateIncidentTests",
        "summary": "Generate regression tests from incident report",
        "description": "Converts an incident or postmortem report into targeted regression test cases using the two-pass Worker + Judge AI pipeline. Consumes CasePilot credits.",
        "tags": [
          "Generation"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IncidentBridgeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generated regression test cases",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IncidentBridgeResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit or usage limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key prefixed with cp_live_ (production) or cp_test_ (testing). Created from the CasePilot extension settings."
      }
    },
    "schemas": {
      "GenerateRequest": {
        "type": "object",
        "required": [
          "title"
        ],
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 500,
            "description": "User story title",
            "example": "User can reset password via email"
          },
          "description": {
            "type": "string",
            "maxLength": 5000,
            "description": "User story description",
            "example": "As a user, I want to reset my password so I can regain access to my account."
          },
          "acceptanceCriteria": {
            "type": "string",
            "maxLength": 5000,
            "description": "Acceptance criteria text",
            "example": "- User receives reset email within 2 minutes\n- Reset link expires after 24 hours"
          },
          "comments": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "maxLength": 2000
            },
            "description": "Discussion comments for additional context"
          },
          "projectKnowledge": {
            "$ref": "#/components/schemas/ProjectKnowledge"
          },
          "settings": {
            "$ref": "#/components/schemas/GenerationSettings"
          }
        }
      },
      "ProjectKnowledge": {
        "type": "object",
        "description": "Project-specific context to improve generation quality",
        "properties": {
          "techStack": {
            "type": "string",
            "maxLength": 2000,
            "description": "Technology stack description",
            "example": "React + Node.js + PostgreSQL"
          },
          "uiComponents": {
            "type": "string",
            "maxLength": 2000,
            "description": "UI component library or patterns used",
            "example": "Material UI v5 with custom theme"
          },
          "businessRules": {
            "type": "string",
            "maxLength": 2000,
            "description": "Domain-specific business rules or constraints",
            "example": "Passwords require 8+ chars, 1 uppercase, 1 number, 1 special"
          },
          "testingConventions": {
            "type": "string",
            "maxLength": 2000,
            "description": "Testing conventions, naming patterns, or frameworks",
            "example": "Playwright + NUnit, Page Object Model pattern"
          }
        }
      },
      "GenerationSettings": {
        "type": "object",
        "description": "Generation configuration",
        "properties": {
          "maxTestCases": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20,
            "default": 5,
            "description": "Number of test cases to generate"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "positive",
                "negative",
                "edge"
              ]
            },
            "default": [
              "positive",
              "negative",
              "edge"
            ],
            "description": "Test case categories to include"
          },
          "includeAutomationHints": {
            "type": "boolean",
            "default": true,
            "description": "Include automation hints (selectors, API calls) in output"
          },
          "automationFramework": {
            "type": "string",
            "enum": [
              "playwright",
              "selenium",
              "cypress",
              "other"
            ],
            "description": "Target automation framework for framework-specific hints (Playwright Locator API, Selenium WebDriver, Cypress commands)"
          }
        }
      },
      "GenerationResponse": {
        "type": "object",
        "properties": {
          "testCases": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TestCase"
            }
          },
          "metadata": {
            "$ref": "#/components/schemas/GenerationMetadata"
          },
          "usage": {
            "$ref": "#/components/schemas/UsageInfo"
          }
        }
      },
      "TestCase": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "description": "Test case title"
          },
          "description": {
            "type": "string",
            "description": "Brief test case description"
          },
          "category": {
            "type": "string",
            "enum": [
              "positive",
              "negative",
              "edge"
            ],
            "description": "Test case category"
          },
          "priority": {
            "type": "integer",
            "minimum": 1,
            "maximum": 4,
            "description": "Priority level: 1 (critical) to 4 (low)"
          },
          "preconditions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Required preconditions before executing"
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TestStep"
            },
            "description": "Ordered test steps"
          },
          "automationHints": {
            "type": "string",
            "nullable": true,
            "description": "Automation guidance (selectors, API calls). Null if includeAutomationHints is false."
          }
        }
      },
      "TestStep": {
        "type": "object",
        "properties": {
          "stepNumber": {
            "type": "integer",
            "description": "Step sequence number"
          },
          "action": {
            "type": "string",
            "description": "Action to perform"
          },
          "expectedResult": {
            "type": "string",
            "description": "Expected outcome of the action"
          },
          "testData": {
            "type": "string",
            "nullable": true,
            "description": "Test data to use for this step"
          }
        }
      },
      "GenerationMetadata": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "description": "AI model used for generation",
            "example": "gpt-4o-mini"
          },
          "tokensUsed": {
            "type": "integer",
            "description": "Total tokens consumed (Worker + Judge passes)"
          },
          "generationTimeMs": {
            "type": "integer",
            "description": "Total generation time in milliseconds"
          },
          "qualityScore": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "description": "Judge-assigned quality score"
          },
          "coverageGaps": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Any identified coverage gaps"
          },
          "judgeNotes": {
            "type": "string",
            "description": "Judge review commentary"
          }
        }
      },
      "UsageInfo": {
        "type": "object",
        "properties": {
          "used": {
            "type": "integer",
            "description": "Test cases generated this period"
          },
          "limit": {
            "type": "integer",
            "description": "Monthly test case limit for your plan"
          },
          "remaining": {
            "type": "integer",
            "description": "Credits remaining this period"
          },
          "planId": {
            "type": "string",
            "description": "Current plan identifier",
            "example": "starter"
          }
        }
      },
      "UsageResponse": {
        "type": "object",
        "properties": {
          "used": {
            "type": "integer",
            "description": "Test cases generated this period",
            "example": 42
          },
          "limit": {
            "type": "integer",
            "description": "Monthly test case limit for your plan",
            "example": 200
          },
          "remaining": {
            "type": "integer",
            "description": "Credits remaining this period",
            "example": 158
          },
          "planId": {
            "type": "string",
            "description": "Current plan identifier",
            "example": "starter"
          },
          "periodStart": {
            "type": "string",
            "format": "date-time",
            "description": "Start of the current billing period",
            "example": "2026-04-01T00:00:00Z"
          },
          "periodEnd": {
            "type": "string",
            "format": "date-time",
            "description": "End of the current billing period",
            "example": "2026-04-30T23:59:59Z"
          }
        }
      },
      "CreateKeyRequest": {
        "type": "object",
        "required": [
          "name",
          "orgId"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Descriptive name for the API key",
            "example": "CI Pipeline Key"
          },
          "orgId": {
            "type": "string",
            "description": "Azure DevOps organization ID",
            "example": "my-organization"
          }
        }
      },
      "CreateKeyResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique key identifier",
            "example": "key_abc123"
          },
          "name": {
            "type": "string",
            "description": "Key name",
            "example": "CI Pipeline Key"
          },
          "key": {
            "type": "string",
            "description": "Full API key value. Only returned once at creation time — store securely.",
            "example": "cp_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Key creation timestamp",
            "example": "2026-04-03T10:00:00Z"
          }
        }
      },
      "ApiKeyInfo": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique key identifier",
            "example": "key_abc123"
          },
          "name": {
            "type": "string",
            "description": "Key name",
            "example": "CI Pipeline Key"
          },
          "maskedKey": {
            "type": "string",
            "description": "Masked key showing only last 4 characters",
            "example": "cp_live_****************************3def"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Key creation timestamp"
          },
          "lastUsedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Last time this key was used"
          }
        }
      },
      "RevokeKeyRequest": {
        "type": "object",
        "required": [
          "keyId"
        ],
        "properties": {
          "keyId": {
            "type": "string",
            "description": "ID of the key to revoke",
            "example": "key_abc123"
          }
        }
      },
      "SprintCoverageRequest": {
        "type": "object",
        "required": [
          "orgId",
          "sprintName",
          "stories"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier",
            "example": "myorg"
          },
          "sprintName": {
            "type": "string",
            "description": "Sprint/iteration path",
            "example": "MyProject\\\\Sprint 5"
          },
          "stories": {
            "type": "array",
            "description": "User Stories to analyze (with test case count from relations)",
            "items": {
              "type": "object",
              "required": [
                "id",
                "title",
                "state",
                "testCaseCount",
                "testCaseIds"
              ],
              "properties": {
                "id": {
                  "type": "integer"
                },
                "title": {
                  "type": "string"
                },
                "state": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "acceptanceCriteria": {
                  "type": "string"
                },
                "priority": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 4
                },
                "storyPoints": {
                  "type": "number"
                },
                "testCaseCount": {
                  "type": "integer"
                },
                "testCaseIds": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        }
      },
      "SprintCoverageResponse": {
        "type": "object",
        "properties": {
          "sprintName": {
            "type": "string"
          },
          "totalStories": {
            "type": "integer"
          },
          "coveredStories": {
            "type": "integer"
          },
          "uncoveredStories": {
            "type": "integer"
          },
          "coveragePercentage": {
            "type": "integer",
            "description": "0-100"
          },
          "riskSummary": {
            "type": "object",
            "properties": {
              "critical": {
                "type": "integer"
              },
              "high": {
                "type": "integer"
              },
              "medium": {
                "type": "integer"
              },
              "low": {
                "type": "integer"
              }
            }
          },
          "topRisks": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "analysisTimeMs": {
            "type": "integer"
          }
        }
      },
      "IncidentBridgeRequest": {
        "type": "object",
        "required": [
          "orgId",
          "incident"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "example": "myorg"
          },
          "incident": {
            "type": "object",
            "required": [
              "title",
              "description"
            ],
            "properties": {
              "title": {
                "type": "string",
                "example": "Payment processing outage — 45min downtime"
              },
              "description": {
                "type": "string",
                "example": "Stripe webhooks stopped processing due to expired TLS certificate"
              },
              "rootCause": {
                "type": "string"
              },
              "impact": {
                "type": "string"
              },
              "affectedSystems": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "timeline": {
                "type": "string"
              },
              "resolution": {
                "type": "string"
              }
            }
          },
          "maxTestCases": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 5
          }
        }
      },
      "IncidentBridgeResponse": {
        "type": "object",
        "properties": {
          "testCases": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "category": {
                  "type": "string",
                  "enum": [
                    "regression",
                    "smoke",
                    "edge"
                  ]
                },
                "priority": {
                  "type": "integer"
                },
                "incidentCoverage": {
                  "type": "string",
                  "description": "Which aspect of the incident this test covers"
                },
                "steps": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/TestStep"
                  }
                }
              }
            }
          },
          "incidentSummary": {
            "type": "string"
          },
          "preventionInsights": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "metadata": {
            "$ref": "#/components/schemas/GenerationMetadata"
          }
        }
      },
      "EnrichStoryRequest": {
        "type": "object",
        "required": [
          "orgId",
          "title"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier",
            "example": "myorg"
          },
          "title": {
            "type": "string",
            "maxLength": 1000,
            "description": "Story title — the seed for enrichment",
            "example": "User can reset password via email"
          },
          "context": {
            "type": "string",
            "maxLength": 10000,
            "description": "Brief context or notes"
          },
          "existingDescription": {
            "type": "string",
            "maxLength": 50000,
            "description": "Existing description to improve (AI enhances rather than generates)"
          },
          "existingAcceptanceCriteria": {
            "type": "string",
            "maxLength": 30000,
            "description": "Existing AC to improve"
          }
        }
      },
      "EnrichStoryResponse": {
        "type": "object",
        "properties": {
          "enrichedStory": {
            "type": "object",
            "properties": {
              "description": {
                "type": "string",
                "description": "Full user story description"
              },
              "acceptanceCriteria": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "text": {
                      "type": "string"
                    },
                    "category": {
                      "type": "string",
                      "enum": [
                        "functional",
                        "non-functional",
                        "edge"
                      ]
                    }
                  }
                }
              },
              "priority": {
                "type": "object",
                "properties": {
                  "level": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 4
                  },
                  "justification": {
                    "type": "string"
                  }
                }
              },
              "storyPoints": {
                "type": "number",
                "description": "Fibonacci estimate (1, 2, 3, 5, 8, 13)"
              },
              "suggestedTags": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "risks": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "definitionOfDone": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "metadata": {
            "$ref": "#/components/schemas/GenerationMetadata"
          },
          "usage": {
            "$ref": "#/components/schemas/UsageInfo"
          }
        }
      },
      "CoverageMatrixRequest": {
        "type": "object",
        "required": [
          "orgId",
          "stories"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier",
            "example": "myorg"
          },
          "stories": {
            "type": "array",
            "maxItems": 500,
            "description": "Stories to analyze",
            "items": {
              "type": "object",
              "required": [
                "id",
                "title",
                "state",
                "testCaseCount",
                "testCaseIds"
              ],
              "properties": {
                "id": {
                  "type": "integer"
                },
                "title": {
                  "type": "string"
                },
                "state": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "acceptanceCriteria": {
                  "type": "string"
                },
                "priority": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 4
                },
                "storyPoints": {
                  "type": "number"
                },
                "testCaseCount": {
                  "type": "integer"
                },
                "testCaseIds": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        }
      },
      "CoverageMatrixResponse": {
        "type": "object",
        "properties": {
          "totalStories": {
            "type": "integer"
          },
          "overallCoverage": {
            "type": "integer",
            "description": "0-100 percentage"
          },
          "testCoverage": {
            "type": "integer"
          },
          "acCoverage": {
            "type": "integer"
          },
          "gapClusters": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string"
                },
                "stories": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                },
                "description": {
                  "type": "string"
                }
              }
            }
          },
          "dependencies": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "storyIds": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                },
                "sharedKeywords": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "analysisTimeMs": {
            "type": "integer"
          }
        }
      },
      "TestHealthRequest": {
        "type": "object",
        "required": [
          "projectId",
          "tests"
        ],
        "properties": {
          "projectId": {
            "type": "string",
            "maxLength": 100,
            "description": "Project identifier",
            "example": "my-project"
          },
          "tests": {
            "type": "array",
            "description": "Test results to analyze",
            "items": {
              "type": "object",
              "required": [
                "name",
                "category",
                "passed",
                "duration",
                "flaky",
                "lastRun"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "description": "Test name"
                },
                "category": {
                  "type": "string",
                  "enum": [
                    "unit",
                    "integration",
                    "e2e",
                    "unknown"
                  ],
                  "description": "Test category"
                },
                "passed": {
                  "type": "boolean",
                  "description": "Whether the test passed"
                },
                "duration": {
                  "type": "number",
                  "description": "Test duration in milliseconds"
                },
                "errorMessage": {
                  "type": "string",
                  "description": "Error message if test failed"
                },
                "flaky": {
                  "type": "boolean",
                  "description": "Whether the test is known to be flaky"
                },
                "lastRun": {
                  "type": "string",
                  "format": "date-time",
                  "description": "ISO date of last run",
                  "example": "2026-04-14T10:00:00Z"
                }
              }
            }
          }
        }
      },
      "TestHealthResponse": {
        "type": "object",
        "properties": {
          "projectId": {
            "type": "string",
            "description": "Project identifier"
          },
          "score": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "description": "Health score (0-100)"
          },
          "grade": {
            "type": "string",
            "enum": [
              "A",
              "B",
              "C",
              "D",
              "F"
            ],
            "description": "Letter grade"
          },
          "factors": {
            "type": "array",
            "description": "Breakdown of scoring factors",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "Factor name (e.g., passRate, flakiness)"
                },
                "score": {
                  "type": "number",
                  "description": "Factor score"
                },
                "weight": {
                  "type": "number",
                  "description": "Factor weight in overall score"
                },
                "detail": {
                  "type": "string",
                  "description": "Human-readable detail"
                }
              }
            }
          },
          "summary": {
            "type": "string",
            "description": "Overall health summary"
          },
          "recommendations": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Actionable recommendations to improve test health"
          }
        }
      },
      "FailureTriageRequest": {
        "type": "object",
        "required": [
          "projectId",
          "failures"
        ],
        "properties": {
          "projectId": {
            "type": "string",
            "maxLength": 100,
            "description": "Project identifier",
            "example": "my-project"
          },
          "failures": {
            "type": "array",
            "description": "Test failures to triage",
            "items": {
              "type": "object",
              "required": [
                "name",
                "errorMessage",
                "duration",
                "occurrences"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "description": "Test name"
                },
                "errorMessage": {
                  "type": "string",
                  "description": "Error message from test failure"
                },
                "stackTrace": {
                  "type": "string",
                  "description": "Stack trace (optional)"
                },
                "category": {
                  "type": "string",
                  "description": "Test category (optional)"
                },
                "duration": {
                  "type": "number",
                  "description": "Test duration in milliseconds"
                },
                "occurrences": {
                  "type": "number",
                  "description": "Number of times this failure occurred"
                },
                "totalRuns": {
                  "type": "number",
                  "description": "Total runs of this test (optional)"
                }
              }
            }
          }
        }
      },
      "FailureTriageResponse": {
        "type": "object",
        "properties": {
          "projectId": {
            "type": "string",
            "description": "Project identifier"
          },
          "groups": {
            "type": "array",
            "description": "Failures grouped by root cause category",
            "items": {
              "type": "object",
              "properties": {
                "category": {
                  "type": "string",
                  "enum": [
                    "timeout",
                    "assertion",
                    "connection",
                    "permission",
                    "resource",
                    "flaky",
                    "unknown"
                  ],
                  "description": "Root cause category"
                },
                "count": {
                  "type": "number",
                  "description": "Number of failures in this group"
                },
                "failures": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  },
                  "description": "Failure objects in this group"
                },
                "rootCause": {
                  "type": "string",
                  "description": "Identified root cause"
                },
                "suggestion": {
                  "type": "string",
                  "description": "Suggested fix or mitigation"
                }
              }
            }
          },
          "summary": {
            "type": "object",
            "properties": {
              "totalFailures": {
                "type": "number",
                "description": "Total number of failures analyzed"
              },
              "groupCount": {
                "type": "number",
                "description": "Number of distinct groups"
              },
              "topCategory": {
                "type": "string",
                "description": "Most common failure category"
              },
              "estimatedFlakyCount": {
                "type": "number",
                "description": "Estimated number of flaky failures"
              }
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Machine-readable error code",
                "example": "VALIDATION_ERROR"
              },
              "message": {
                "type": "string",
                "description": "Human-readable error message",
                "example": "Field 'title' is required and must not be empty."
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Generation",
      "description": "AI test case generation endpoints"
    },
    {
      "name": "StoryPilot",
      "description": "AI-powered User Story enrichment"
    },
    {
      "name": "Coverage",
      "description": "Sprint test coverage and cross-story matrix analysis"
    },
    {
      "name": "Test Intelligence",
      "description": "Test health scoring and failure triage analysis"
    },
    {
      "name": "Usage",
      "description": "Credit usage and billing information"
    },
    {
      "name": "API Keys",
      "description": "API key management"
    }
  ]
}