{
  "openapi": "3.1.0",
  "info": {
    "title": "Ranka Publishing API",
    "version": "1.0.0",
    "description": "Receiver-pull integration for a CMS adapter. Replace the server URL with the deployed Ranka origin."
  },
  "servers": [
    { "url": "https://YOUR_STUDIO_HOST", "description": "Replace with the deployed Ranka origin" }
  ],
  "security": [{ "WebsiteBearerToken": [] }],
  "components": {
    "securitySchemes": {
      "WebsiteBearerToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "Website-scoped token. Keep it on the CMS receiver server; never expose it in browser code."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": { "error": { "type": "string" } },
        "required": ["error"]
      },
      "QueuedArticle": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "topicId": { "type": "string", "format": "uuid" },
          "title": { "type": "string" },
          "metaDescription": { "type": "string" },
          "suggestedSlug": { "type": "string" },
          "excerpt": { "type": "string" },
          "contentMarkdown": { "type": "string" },
          "category": { "type": "string" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "targetKeyword": { "type": "string" },
          "approvedAt": { "type": "string", "format": "date-time" }
        },
        "required": ["id", "topicId", "title", "metaDescription", "suggestedSlug", "excerpt", "contentMarkdown", "category", "tags", "targetKeyword", "approvedAt"]
      }
    }
  },
  "paths": {
    "/api/v1/integrations/verify": {
      "post": {
        "operationId": "verifyWebsiteIntegration",
        "summary": "Verify the website token",
        "description": "Requires the integration:verify scope. Send an empty body or {}.",
        "responses": {
          "200": { "description": "Token verified and website identity returned" },
          "401": { "description": "Invalid, expired, or revoked token", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "Token lacks the required scope", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/v1/publishing/queue": {
      "get": {
        "operationId": "getApprovedArticleQueue",
        "summary": "List approved, unpublished articles",
        "description": "Requires content:read. Results are scoped to the website associated with the token.",
        "parameters": [
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 20 } }
        ],
        "responses": {
          "200": {
            "description": "Approved article queue",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "articles": { "type": "array", "items": { "$ref": "#/components/schemas/QueuedArticle" } } }, "required": ["articles"] } } }
          },
          "401": { "description": "Invalid token", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "Token lacks content:read", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/v1/publishing/articles/{articleId}": {
      "get": {
        "operationId": "getApprovedArticle",
        "summary": "Fetch an approved article",
        "parameters": [
          { "name": "articleId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": { "description": "Article content and status" },
          "404": { "description": "Article not found or not approved/published", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/v1/publishing/articles/{articleId}/publication": {
      "post": {
        "operationId": "acknowledgePublishedArticle",
        "summary": "Record a successful CMS publish",
        "description": "Requires content:publish. Call only after the CMS confirms publication. The URL is recorded but not crawled or independently verified. Retain and reuse the idempotency key when retrying.",
        "parameters": [
          { "name": "articleId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } },
          { "name": "Idempotency-Key", "in": "header", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "properties": { "publishedUrl": { "type": "string", "format": "uri", "description": "Must use HTTPS" }, "externalId": { "type": "string", "maxLength": 240 }, "publishedAt": { "type": "string", "format": "date-time" } }, "required": ["publishedUrl"], "additionalProperties": false } } }
        },
        "responses": {
          "201": { "description": "Publication recorded" },
          "409": { "description": "Article not approved, already published, or idempotency conflict", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  }
}
