{
  "openapi": "3.0.3",
  "info": {
    "title": "Docuplate public PDF API",
    "description": "Generate PDFs from saved templates with an API key (Pro and Business). Webhooks and public forms on every plan are documented at /guides.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://www.docuplate.io",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/public/templates/{templateId}/generate": {
      "post": {
        "operationId": "generatePdf",
        "summary": "Generate a PDF from a template",
        "description": "Same render pipeline as the builder. Omit data to use the template sample payload (smoke tests only). Pass async=true to queue a job and poll GET /api/public/jobs/{jobId}.",
        "security": [{ "ApiKeyAuth": [] }],
        "parameters": [
          {
            "name": "templateId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "async",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["true"] }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "data": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "JSON payload matching the template field paths."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "PDF generated, or async job accepted",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    { "$ref": "#/components/schemas/GenerateResult" },
                    { "$ref": "#/components/schemas/AsyncJobAccepted" }
                  ]
                }
              }
            }
          },
          "401": { "description": "Missing or invalid API key" },
          "403": { "description": "Plan does not include API keys" },
          "404": { "description": "Template not found" }
        }
      }
    },
    "/api/public/jobs/{jobId}": {
      "get": {
        "operationId": "getGenerateJob",
        "summary": "Poll an async generate job",
        "security": [{ "ApiKeyAuth": [] }],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Job record",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "job": { "$ref": "#/components/schemas/AsyncJob" }
                  }
                }
              }
            }
          },
          "401": { "description": "Missing or invalid API key" },
          "404": { "description": "Job not found" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "df_",
        "description": "API key created in the app. Header: Authorization: Bearer df_…"
      }
    },
    "schemas": {
      "GenerateResult": {
        "type": "object",
        "properties": {
          "fileUrl": { "type": "string" },
          "generatedPdfId": { "type": "string", "nullable": true },
          "warnings": { "type": "array", "items": { "type": "string" } },
          "errors": { "type": "array", "items": { "type": "string" } },
          "status": { "type": "string" }
        }
      },
      "AsyncJobAccepted": {
        "type": "object",
        "properties": {
          "jobId": { "type": "string" },
          "status": { "type": "string", "example": "pending" }
        }
      },
      "AsyncJob": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "status": { "type": "string" },
          "generatedPdfId": { "type": "string", "nullable": true },
          "errorMessage": { "type": "string", "nullable": true }
        }
      }
    }
  }
}
