{
  "openapi": "3.1.0",
  "info": {
    "title": "stratum-api",
    "description": "",
    "license": {
      "name": ""
    },
    "version": "0.1.0"
  },
  "paths": {
    "/api/analytics/bin-definitions": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "GET /api/analytics/bin-definitions?lot_id=CDK70001",
        "description": "Returns bin name labels from HBR/SBR records for a lot's test program.",
        "operationId": "bin_definitions",
        "parameters": [
          {
            "name": "lot_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_job_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Bin name labels from the lot test program",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/BinDefinition"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Lot not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/analytics/bin-summary": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "GET /api/analytics/bin-summary?lot_id=LOT-2024-0341",
        "operationId": "bin_summary",
        "parameters": [
          {
            "name": "lot_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_job_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Per-wafer bin distribution summary",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/BinSummaryRow"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Lot or snapshot not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/analytics/cpk": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "GET /api/analytics/cpk?lot_id=LOT-2024-0341\nWithout wafer_number: returns lot-level CPK (one row per test, pooled across wafers).\nWith wafer_number: returns per-wafer CPK for that wafer.",
        "description": "Query-time behavior is governed by analysis defaults (retest handling,\nsite aggregation, outlier exclusion) stored per-account in Postgres.",
        "operationId": "cpk",
        "parameters": [
          {
            "name": "lot_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_job_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "wafer_number",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Capability and distribution summary rows",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/CpkRow"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Lot or snapshot not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/analytics/die-map": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "GET /api/analytics/die-map?lot_id=LOT-2024-0341&wafer_number=1",
        "operationId": "die_map",
        "parameters": [
          {
            "name": "lot_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_job_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "wafer_number",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Final die map for one wafer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DieMapRow"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Lot or snapshot not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/analytics/die-maps": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "GET /api/analytics/die-maps?lot_id=LOT-2024-0341",
        "description": "Returns all wafers' die maps in a single DuckDB query, avoiding\nper-wafer connection setup and S3 glob overhead.",
        "operationId": "die_maps_batch",
        "parameters": [
          {
            "name": "lot_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_job_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Final die maps for all wafers in the lot",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Lot or snapshot not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/analytics/lot-info": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "GET /api/analytics/lot-info?lot_id=CDK70001",
        "operationId": "lot_info",
        "parameters": [
          {
            "name": "lot_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_job_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Rich lot metadata and ingest summary",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LotInfo"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Lot or snapshot not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/analytics/test-results": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "GET /api/analytics/test-results?lot_id=LOT-2024-0341&test_number=100",
        "operationId": "test_results",
        "parameters": [
          {
            "name": "lot_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_job_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "wafer_number",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "test_number",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32",
              "minimum": 0
            }
          },
          {
            "name": "limit_rows",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Die-level parametric test results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/TestResultRow"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Lot or snapshot not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/analytics/wafers": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "GET /api/analytics/wafers?lot_id=LOT-2024-0341",
        "operationId": "wafers",
        "parameters": [
          {
            "name": "lot_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "snapshot_job_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Wafer summaries for a lot",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WaferSummary"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Lot or snapshot not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/ingest-jobs": {
      "get": {
        "tags": [
          "ingest"
        ],
        "summary": "GET /api/ingest-jobs — list jobs for the account.",
        "operationId": "list",
        "responses": {
          "200": {
            "description": "Recent ingest jobs for the account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/IngestJob"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/ingest-jobs/{id}": {
      "get": {
        "tags": [
          "ingest"
        ],
        "summary": "GET /api/ingest-jobs/:id — get a single job by ID.",
        "operationId": "get",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Ingest job id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ingest job detail",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestJob"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Job not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/ingest-jobs/{id}/events": {
      "get": {
        "tags": [
          "ingest"
        ],
        "summary": "GET /api/ingest-jobs/:id/events — event trail for a single job.",
        "operationId": "list",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Ingest job id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Event trail for the ingest job",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/IngestEvent"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/lots": {
      "get": {
        "tags": [
          "lots"
        ],
        "summary": "GET /api/lots — returns lots scoped by PL membership for non-admins.",
        "operationId": "list",
        "responses": {
          "200": {
            "description": "Lots visible to the caller",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/LotSummary"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/sql/examples": {
      "get": {
        "tags": [
          "sql"
        ],
        "operationId": "examples",
        "responses": {
          "200": {
            "description": "Built-in SQL examples",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExamplesResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/sql/query": {
      "post": {
        "tags": [
          "sql"
        ],
        "operationId": "execute_query",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QueryRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Execute SQL query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QueryResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query or timed out",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/sql/schema": {
      "get": {
        "tags": [
          "sql"
        ],
        "operationId": "schema",
        "responses": {
          "200": {
            "description": "Discover SQL schema",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchemaResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/upload": {
      "post": {
        "tags": [
          "ingest"
        ],
        "summary": "POST /api/upload — multipart STDF upload.",
        "description": "Stores the file in MinIO under `{account_id}/{job_id}/{filename}`,\ncreates an `ingest_jobs` row with status=pending, and returns the job ID.\n\nAccepts optional headers:\n- `X-Content-SHA256`: client-side checksum for early dedup (before reading body)\n- `X-Force-Reingest: true`: skip dedup, allow re-upload of identical file\n\nAccepts optional multipart fields:\n- `lot_id`: override MIR lot ID for this ingest\n- `tags`: JSON string array or comma-separated tags",
        "operationId": "create",
        "parameters": [
          {
            "name": "parse_mode",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "parser_profile_id",
            "in": "query",
            "description": "If set, overrides parse_mode with the profile's settings.",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "x-content-sha256",
            "in": "header",
            "description": "Optional client-side SHA256 checksum",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "name": "x-force-reingest",
            "in": "header",
            "description": "Set to true to bypass duplicate rejection",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        ],
        "requestBody": {
          "description": "Multipart STDF upload with optional lot_id and tags fields",
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/UploadMultipartForm"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Created ingest job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid upload or parse mode",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Parser profile not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "description": "Duplicate file conflict",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/api/upload/inspect": {
      "post": {
        "tags": [
          "ingest"
        ],
        "summary": "POST /api/upload/inspect — lightweight STDF metadata preview before upload.",
        "operationId": "inspect",
        "parameters": [
          {
            "name": "parse_mode",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "parser_profile_id",
            "in": "query",
            "description": "If set, overrides parse_mode with the profile's settings.",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "description": "Multipart STDF preview request",
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/UploadMultipartForm"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Parsed STDF metadata preview",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadInspectResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid preview request or parse failure",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Parser profile not found",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer_auth": []
          }
        ]
      }
    },
    "/health": {
      "get": {
        "tags": [
          "health"
        ],
        "summary": "Unauthenticated health check — used by load balancers and compose healthchecks.",
        "operationId": "get",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AnalysisScopeRequest": {
        "type": "object",
        "required": [
          "lot_id",
          "selection_active",
          "selection_die_count"
        ],
        "properties": {
          "lot_id": {
            "type": "string"
          },
          "scenario_limits": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ScenarioLimitRequest"
            }
          },
          "selected_dies": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SelectedDieRequest"
            }
          },
          "selected_test_number": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "selected_wafer_number": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "selection_active": {
            "type": "boolean"
          },
          "selection_die_count": {
            "type": "integer",
            "minimum": 0
          },
          "snapshot_job_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "BinDefinition": {
        "type": "object",
        "required": [
          "bin_number",
          "bin_type",
          "pass_fail"
        ],
        "properties": {
          "bin_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "bin_number": {
            "type": "integer",
            "format": "int32"
          },
          "bin_type": {
            "type": "string"
          },
          "pass_fail": {
            "type": "string"
          }
        }
      },
      "BinSummaryRow": {
        "type": "object",
        "required": [
          "wafer_number",
          "bin_number",
          "bin_type",
          "count",
          "pct"
        ],
        "properties": {
          "bin_number": {
            "type": "integer",
            "format": "int32"
          },
          "bin_type": {
            "type": "string"
          },
          "count": {
            "type": "integer",
            "format": "int32"
          },
          "pct": {
            "type": "number",
            "format": "double"
          },
          "wafer_number": {
            "type": "integer",
            "format": "int32"
          }
        }
      },
      "ColumnMeta": {
        "type": "object",
        "required": [
          "name",
          "type"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string"
          }
        }
      },
      "CpkQuery": {
        "type": "object",
        "required": [
          "lot_id"
        ],
        "properties": {
          "lot_id": {
            "type": "string"
          },
          "snapshot_job_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "wafer_number": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          }
        }
      },
      "CpkRow": {
        "type": "object",
        "required": [
          "test_number",
          "test_name",
          "n",
          "mean",
          "pass_count",
          "fail_count",
          "counts_estimated"
        ],
        "properties": {
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "counts_estimated": {
            "type": "boolean"
          },
          "cp": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "cpk": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "fail_count": {
            "type": "integer",
            "format": "int32"
          },
          "high_limit": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "high_spec": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "kurtosis": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "low_limit": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "low_spec": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "max": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "mean": {
            "type": "number",
            "format": "double"
          },
          "min": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "n": {
            "type": "integer",
            "format": "int32"
          },
          "p25": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "p5": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "p50": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "p75": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "p95": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "pass_count": {
            "type": "integer",
            "format": "int32"
          },
          "pp": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "ppk": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "site": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "skewness": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "spec_cp": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "spec_cpk": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "spec_pp": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "spec_ppk": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "std": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "test_name": {
            "type": "string"
          },
          "test_number": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "unit": {
            "type": [
              "string",
              "null"
            ]
          },
          "within_std": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          }
        }
      },
      "DieMapQuery": {
        "type": "object",
        "required": [
          "lot_id",
          "wafer_number"
        ],
        "properties": {
          "lot_id": {
            "type": "string"
          },
          "snapshot_job_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "wafer_number": {
            "type": "integer",
            "format": "int32"
          }
        }
      },
      "DieMapRow": {
        "type": "object",
        "required": [
          "x",
          "y",
          "hard_bin",
          "pass"
        ],
        "properties": {
          "hard_bin": {
            "type": "integer",
            "format": "int32"
          },
          "part_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "pass": {
            "type": "boolean"
          },
          "soft_bin": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "test_time_ms": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "x": {
            "type": "integer",
            "format": "int32"
          },
          "y": {
            "type": "integer",
            "format": "int32"
          }
        }
      },
      "DieMapsBatchQuery": {
        "type": "object",
        "required": [
          "lot_id"
        ],
        "properties": {
          "lot_id": {
            "type": "string"
          },
          "snapshot_job_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "ExampleQuery": {
        "type": "object",
        "required": [
          "name",
          "sql"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "sql": {
            "type": "string"
          }
        }
      },
      "ExamplesResponse": {
        "type": "object",
        "required": [
          "examples"
        ],
        "properties": {
          "examples": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ExampleQuery"
            }
          }
        }
      },
      "IngestEvent": {
        "type": "object",
        "required": [
          "id",
          "job_id",
          "event",
          "occurred_at",
          "detail"
        ],
        "properties": {
          "detail": {
            "type": "object"
          },
          "event": {
            "type": "string"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "job_id": {
            "type": "string",
            "format": "uuid"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "IngestJob": {
        "type": "object",
        "required": [
          "id",
          "status",
          "parse_mode",
          "reviewed_metadata",
          "parse_warnings",
          "corrections_applied",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "corrections_applied": {
            "type": "object"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "dib_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "facility": {
            "type": [
              "string",
              "null"
            ]
          },
          "filename": {
            "type": [
              "string",
              "null"
            ]
          },
          "floor": {
            "type": [
              "string",
              "null"
            ]
          },
          "flow_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "handler_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "head_num": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "load_board_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "lot_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "matched_rule_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "node_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "parse_mode": {
            "type": "string"
          },
          "parse_warnings": {
            "type": "object"
          },
          "parsed_lot_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "parser_profile_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "probe_card_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "raw_test_temperature": {
            "type": [
              "string",
              "null"
            ]
          },
          "record_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "reviewed_metadata": {
            "type": "object"
          },
          "setup_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "site_group": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "status": {
            "type": "string"
          },
          "tags": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "tester": {
            "type": [
              "string",
              "null"
            ]
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "wafer_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          }
        }
      },
      "LotInfo": {
        "type": "object",
        "description": "Rich lot metadata assembled from ingest_jobs metadata JSONB.",
        "required": [
          "lot_id",
          "reviewed_metadata"
        ],
        "properties": {
          "corrections_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "dib_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "die_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "facility": {
            "type": [
              "string",
              "null"
            ]
          },
          "filename": {
            "type": [
              "string",
              "null"
            ]
          },
          "finish_time": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "floor": {
            "type": [
              "string",
              "null"
            ]
          },
          "flow_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "handler_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "head_num": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "integrity_pct": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "job_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "load_board_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "lot_id": {
            "type": "string"
          },
          "node_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "parse_errors": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "parse_mode": {
            "type": [
              "string",
              "null"
            ]
          },
          "parsed_lot_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "probe_card_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "process_node": {
            "type": [
              "string",
              "null"
            ]
          },
          "product": {
            "type": [
              "string",
              "null"
            ]
          },
          "raw_test_temperature": {
            "type": [
              "string",
              "null"
            ]
          },
          "record_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "record_counts": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": {
              "type": "integer",
              "format": "int64"
            },
            "propertyNames": {
              "type": "string"
            }
          },
          "reviewed_metadata": {
            "type": "object"
          },
          "setup_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "site_group": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "start_time": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "tags": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "tester": {
            "type": [
              "string",
              "null"
            ]
          },
          "total_tests": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "unique_params": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "unknown_records": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "wafer_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "warnings_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          }
        }
      },
      "LotSummary": {
        "type": "object",
        "description": "Lot summary returned by GET /api/lots.",
        "required": [
          "id",
          "lot_id",
          "has_analyzable_snapshot"
        ],
        "properties": {
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "die_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "has_analyzable_snapshot": {
            "type": "boolean"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "latest_ingest_error": {
            "type": [
              "string",
              "null"
            ]
          },
          "latest_ingest_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "latest_ingested_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lot_id": {
            "type": "string"
          },
          "process_node": {
            "type": [
              "string",
              "null"
            ]
          },
          "product": {
            "type": [
              "string",
              "null"
            ]
          },
          "tags": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "tested_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "wafer_count": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          }
        }
      },
      "PlainTextError": {
        "type": "object",
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string"
          }
        }
      },
      "QueryRequest": {
        "type": "object",
        "required": [
          "sql"
        ],
        "properties": {
          "analysis_scope": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/AnalysisScopeRequest"
              }
            ]
          },
          "limit": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "offset": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "sql": {
            "type": "string"
          }
        }
      },
      "QueryResponse": {
        "type": "object",
        "required": [
          "columns",
          "rows",
          "row_count",
          "total_row_count",
          "truncated",
          "page_limit",
          "page_offset",
          "elapsed_ms"
        ],
        "properties": {
          "columns": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ColumnMeta"
            }
          },
          "elapsed_ms": {
            "type": "number",
            "format": "double"
          },
          "page_limit": {
            "type": "integer",
            "minimum": 0
          },
          "page_offset": {
            "type": "integer",
            "minimum": 0
          },
          "row_count": {
            "type": "integer",
            "minimum": 0
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "object"
              }
            }
          },
          "total_row_count": {
            "type": "integer",
            "minimum": 0
          },
          "truncated": {
            "type": "boolean"
          }
        }
      },
      "ScenarioLimitRequest": {
        "type": "object",
        "required": [
          "test_number",
          "test_name"
        ],
        "properties": {
          "lsl": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "test_name": {
            "type": "string"
          },
          "test_number": {
            "type": "integer",
            "format": "int32"
          },
          "usl": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          }
        }
      },
      "SchemaResponse": {
        "type": "object",
        "required": [
          "tables"
        ],
        "properties": {
          "tables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TableSchema"
            }
          }
        }
      },
      "SelectedDieRequest": {
        "type": "object",
        "required": [
          "wafer_number",
          "x",
          "y"
        ],
        "properties": {
          "wafer_number": {
            "type": "integer",
            "format": "int32"
          },
          "x": {
            "type": "integer",
            "format": "int32"
          },
          "y": {
            "type": "integer",
            "format": "int32"
          }
        }
      },
      "TableSchema": {
        "type": "object",
        "required": [
          "name",
          "columns"
        ],
        "properties": {
          "columns": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ColumnMeta"
            }
          },
          "name": {
            "type": "string"
          }
        }
      },
      "TestResultQuery": {
        "type": "object",
        "required": [
          "lot_id"
        ],
        "properties": {
          "limit_rows": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "lot_id": {
            "type": "string"
          },
          "snapshot_job_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "test_number": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32",
            "minimum": 0
          },
          "wafer_number": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          }
        }
      },
      "TestResultRow": {
        "type": "object",
        "required": [
          "wafer_number",
          "x",
          "y",
          "test_number",
          "test_name",
          "unit",
          "pass",
          "effective_pass",
          "retest_sequence"
        ],
        "properties": {
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "effective_high_limit": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "effective_low_limit": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "effective_pass": {
            "type": "boolean"
          },
          "high_limit": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "high_spec": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "low_limit": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "low_spec": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "pass": {
            "type": "boolean"
          },
          "result": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          },
          "retest_sequence": {
            "type": "integer",
            "format": "int32"
          },
          "test_name": {
            "type": "string"
          },
          "test_number": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "unit": {
            "type": "string"
          },
          "wafer_number": {
            "type": "integer",
            "format": "int32"
          },
          "x": {
            "type": "integer",
            "format": "int32"
          },
          "y": {
            "type": "integer",
            "format": "int32"
          }
        }
      },
      "UploadInspectResponse": {
        "type": "object",
        "required": [
          "filename",
          "parse_mode",
          "parsed_lot_id",
          "record_count",
          "wafer_count",
          "parse_errors",
          "warnings_count"
        ],
        "properties": {
          "dib_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "facility": {
            "type": [
              "string",
              "null"
            ]
          },
          "filename": {
            "type": "string"
          },
          "floor": {
            "type": [
              "string",
              "null"
            ]
          },
          "flow_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "handler_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "head_num": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "load_board_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "matched_rule_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "matched_rule_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "node_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "osat_site_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "parse_errors": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "parse_mode": {
            "type": "string"
          },
          "parsed_lot_id": {
            "type": "string"
          },
          "parser_profile_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "parser_profile_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "probe_card_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "raw_test_temperature": {
            "type": [
              "string",
              "null"
            ]
          },
          "record_count": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "setup_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "site_group": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int32"
          },
          "tester": {
            "type": [
              "string",
              "null"
            ]
          },
          "wafer_count": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "warnings_count": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "UploadMultipartForm": {
        "type": "object",
        "required": [
          "file"
        ],
        "properties": {
          "file": {
            "type": "string",
            "format": "binary"
          },
          "lot_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "metadata_review": {
            "type": [
              "string",
              "null"
            ]
          },
          "tags": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "UploadQuery": {
        "type": "object",
        "properties": {
          "parse_mode": {
            "type": "string"
          },
          "parser_profile_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "If set, overrides parse_mode with the profile's settings."
          }
        }
      },
      "UploadResponse": {
        "type": "object",
        "required": [
          "job_id",
          "filename",
          "status"
        ],
        "properties": {
          "filename": {
            "type": "string"
          },
          "job_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string"
          }
        }
      },
      "WaferQuery": {
        "type": "object",
        "required": [
          "lot_id"
        ],
        "properties": {
          "lot_id": {
            "type": "string"
          },
          "snapshot_job_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "WaferSummary": {
        "type": "object",
        "required": [
          "wafer_id",
          "wafer_number",
          "total_die",
          "pass_die",
          "fail_die",
          "first_pass_yield_pct",
          "final_yield_pct",
          "retest_count"
        ],
        "properties": {
          "fail_die": {
            "type": "integer",
            "format": "int64"
          },
          "final_yield_pct": {
            "type": "number",
            "format": "double"
          },
          "first_pass_yield_pct": {
            "type": "number",
            "format": "double"
          },
          "pass_die": {
            "type": "integer",
            "format": "int64"
          },
          "retest_count": {
            "type": "integer",
            "format": "int32"
          },
          "test_time_ms": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "total_die": {
            "type": "integer",
            "format": "int64"
          },
          "wafer_id": {
            "type": "string"
          },
          "wafer_number": {
            "type": "integer",
            "format": "int32"
          }
        }
      }
    },
    "securitySchemes": {
      "bearer_auth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "tags": [
    {
      "name": "health",
      "description": "Unauthenticated health and readiness surface"
    },
    {
      "name": "ingest",
      "description": "Public ingest surface. All authenticated routes use bearer tokens. Service-account API keys are exchanged into bearer tokens and then limited by ingest, read, or full scope."
    },
    {
      "name": "lots",
      "description": "Public lot listing surface. Authenticated with bearer tokens. Service-account scopes are enforced server-side."
    },
    {
      "name": "analytics",
      "description": "Public read-side analytics surface. Supports live or pinned snapshot reads via snapshot_job_id. Authenticated with bearer tokens."
    },
    {
      "name": "sql",
      "description": "Public SQL surface. Read-only validation plus sandbox limits apply. Schema and examples work with read or full scope; query execution requires full."
    }
  ]
}
