{
  "openapi": "3.0.3",
  "info": {
    "title": "Tataru API",
    "version": "1.0.0",
    "description": "Issue tracker for humans and AI agents. All /api/v1 endpoints except this document require 'Authorization: Bearer <token>'. Errors are {\"error\": \"message\"}."
  },
  "components": {
    "securitySchemes": { "bearer": { "type": "http", "scheme": "bearer" } },
    "schemas": {
      "Project": { "type": "object", "properties": { "id": {"type":"integer"}, "key": {"type":"string","example":"TAT"}, "name": {"type":"string"} } },
      "Issue": {
        "type": "object",
        "properties": {
          "id": {"type":"string","example":"TAT-12"}, "project": {"type":"string"}, "number": {"type":"integer"},
          "title": {"type":"string"}, "body": {"type":"string"},
          "status": {"type":"string","enum":["open","in_progress","done","closed"]},
          "priority": {"type":"string","enum":["low","medium","high","urgent"]},
          "assignee": {"type":"string"}, "labels": {"type":"array","items":{"type":"string"}},
          "created_by": {"type":"string"}, "created_at": {"type":"string","format":"date-time"}, "updated_at": {"type":"string","format":"date-time"}
        }
      },
      "IssuePatch": {
        "type": "object",
        "description": "Any subset of fields; omitted fields are unchanged.",
        "properties": {
          "title": {"type":"string"}, "body": {"type":"string"},
          "status": {"type":"string","enum":["open","in_progress","done","closed"]},
          "priority": {"type":"string","enum":["low","medium","high","urgent"]},
          "assignee": {"type":"string"}, "labels": {"type":"array","items":{"type":"string"}}
        }
      },
      "Comment": { "type": "object", "properties": { "id": {"type":"integer"}, "issue_id": {"type":"string"}, "body": {"type":"string"}, "author": {"type":"string"}, "created_at": {"type":"string","format":"date-time"} } },
      "Error": { "type": "object", "properties": { "error": {"type":"string"} } }
    }
  },
  "security": [{ "bearer": [] }],
  "paths": {
    "/healthz": { "get": { "security": [], "summary": "Liveness", "responses": { "200": {"description":"ok"} } } },
    "/api/v1/openapi.json": { "get": { "security": [], "summary": "This document", "responses": { "200": {"description":"OpenAPI document"} } } },
    "/api/v1/projects": {
      "get": { "summary": "List projects", "responses": { "200": {"description":"Projects", "content": {"application/json": {"schema": {"type":"array","items":{"$ref":"#/components/schemas/Project"}}}}} } },
      "post": { "summary": "Create a project (key: 2-10 chars A-Z0-9, starts with a letter)",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type":"object","required":["key","name"],"properties":{"key":{"type":"string"},"name":{"type":"string"}}}}}},
        "responses": { "201": {"description":"Created"}, "400": {"description":"Invalid"} } }
    },
    "/api/v1/issues": {
      "get": { "summary": "List/search issues (max 200, newest-updated first)",
        "parameters": [
          {"name":"project","in":"query","schema":{"type":"string"}},
          {"name":"status","in":"query","schema":{"type":"string"}},
          {"name":"assignee","in":"query","schema":{"type":"string"}},
          {"name":"label","in":"query","schema":{"type":"string"}},
          {"name":"q","in":"query","description":"Case-insensitive substring of title or body","schema":{"type":"string"}}
        ],
        "responses": { "200": {"description":"Issues","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Issue"}}}}}, "400": {"description":"Invalid filter"} } },
      "post": { "summary": "Create an issue (set priority/labels/assignee afterwards with PATCH)",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type":"object","required":["project","title"],"properties":{"project":{"type":"string","example":"TAT"},"title":{"type":"string"},"body":{"type":"string"}}}}}},
        "responses": { "201": {"description":"Created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Issue"}}}}, "400": {"description":"Invalid"}, "404": {"description":"Unknown project"} } }
    },
    "/api/v1/issues/{id}": {
      "parameters": [{"name":"id","in":"path","required":true,"schema":{"type":"string","example":"TAT-12"}}],
      "get": { "summary": "Get an issue", "responses": { "200": {"description":"Issue","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Issue"}}}}, "404": {"description":"Not found"} } },
      "patch": { "summary": "Update an issue",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref":"#/components/schemas/IssuePatch"}}}},
        "responses": { "200": {"description":"Updated issue"}, "400": {"description":"Invalid"}, "404": {"description":"Not found"} } }
    },
    "/api/v1/issues/{id}/comments": {
      "parameters": [{"name":"id","in":"path","required":true,"schema":{"type":"string","example":"TAT-12"}}],
      "get": { "summary": "List comments", "responses": { "200": {"description":"Comments","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Comment"}}}}}, "404": {"description":"Not found"} } },
      "post": { "summary": "Add a comment",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type":"object","required":["body"],"properties":{"body":{"type":"string"}}}}}},
        "responses": { "201": {"description":"Created"}, "400": {"description":"Invalid"}, "404": {"description":"Not found"} } }
    }
  }
}
