{
  "openapi": "3.1.0",
  "info": {
    "title": "in-answer Blog API",
    "version": "1.0.0",
    "description": "REST API for creating, updating, and publishing blog posts on in-answer.ai. Requires an API key.",
    "contact": { "name": "in-answer", "url": "https://in-answer.ai/#contact" }
  },
  "servers": [
    { "url": "https://xadbqmpogsskiwmstywo.supabase.co/functions/v1/blog-api" }
  ],
  "security": [{ "ApiKeyAuth": [] }],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": { "type": "apiKey", "in": "header", "name": "x-api-key" }
    },
    "schemas": {
      "Post": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "slug": { "type": "string" },
          "title": { "type": "string" },
          "excerpt": { "type": "string" },
          "content_html": { "type": "string" },
          "cover_image_url": { "type": "string" },
          "og_image_url": { "type": "string" },
          "status": { "type": "string", "enum": ["draft", "published", "scheduled"] },
          "scheduled_for": { "type": "string", "format": "date-time" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "meta_title": { "type": "string" },
          "meta_description": { "type": "string" },
          "faq": { "type": "array", "items": { "type": "object" } },
          "author_name": { "type": "string" },
          "reading_minutes": { "type": "integer" },
          "published_at": { "type": "string", "format": "date-time" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "Error": { "type": "object", "properties": { "error": {} } }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "security": [],
        "responses": { "200": { "description": "Service is healthy", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string" }, "service": { "type": "string" }, "time": { "type": "string", "format": "date-time" } } } } } } }
      }
    },
    "/posts": {
      "get": {
        "summary": "List posts",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 20, "maximum": 100 } },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["draft", "published", "scheduled"] } }
        ],
        "responses": {
          "200": { "description": "List of posts", "content": { "application/json": { "schema": { "type": "object", "properties": { "posts": { "type": "array", "items": { "$ref": "#/components/schemas/Post" } } } } } } },
          "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "post": {
        "summary": "Create a post",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Post" } } } },
        "responses": {
          "201": { "description": "Created", "content": { "application/json": { "schema": { "type": "object", "properties": { "post": { "$ref": "#/components/schemas/Post" } } } } } },
          "400": { "description": "Validation error" },
          "409": { "description": "Slug already exists" }
        }
      }
    },
    "/posts/{slug}": {
      "parameters": [{ "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
      "get": {
        "summary": "Get a post by slug",
        "responses": {
          "200": { "description": "Post", "content": { "application/json": { "schema": { "type": "object", "properties": { "post": { "$ref": "#/components/schemas/Post" } } } } } },
          "404": { "description": "Not found" }
        }
      },
      "patch": {
        "summary": "Update a post",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Post" } } } },
        "responses": { "200": { "description": "Updated" }, "404": { "description": "Not found" } }
      },
      "put": {
        "summary": "Update a post (alias of PATCH)",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Post" } } } },
        "responses": { "200": { "description": "Updated" }, "404": { "description": "Not found" } }
      },
      "delete": {
        "summary": "Delete a post",
        "responses": { "200": { "description": "Deleted" }, "404": { "description": "Not found" } }
      }
    }
  }
}
