{
  "openapi": "3.1.0",
  "info": {
    "title": "PageBaton Publishing API",
    "version": "1.0.0",
    "description": "Account-scoped project listing and asynchronous publishing endpoints. Paths are relative to the PageBaton console."
  },
  "servers": [
    {
      "url": "/api/v1"
    }
  ],
  "security": [
    {
      "ProjectKey": []
    }
  ],
  "paths": {
    "/projects": {
      "get": {
        "operationId": "listProjects",
        "summary": "List owned projects",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projects": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Project"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/projects/{id}": {
      "get": {
        "operationId": "getProject",
        "summary": "Read current project revision",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "renameProject",
        "summary": "Rename an owned project",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "displayName": {
                    "type": "string"
                  },
                  "expectedRevision": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": ["displayName", "expectedRevision"]
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/drafts": {
      "post": {
        "operationId": "createDraft",
        "summary": "Create a private upload draft",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Draft"
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "fileName": {
                    "type": "string"
                  },
                  "projectId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "expectedRevision": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": ["fileName"]
              }
            }
          }
        }
      }
    },
    "/drafts/{id}": {
      "get": {
        "operationId": "getDraft",
        "summary": "Read preparation status",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Draft"
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/drafts/{id}/source": {
      "put": {
        "operationId": "uploadSource",
        "summary": "Upload original file bytes",
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Draft"
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/drafts/{id}/entry": {
      "patch": {
        "operationId": "chooseEntry",
        "summary": "Choose a candidate entry from an archive",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Draft"
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "entry": {
                    "type": "string"
                  },
                  "expectedRevision": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": ["entry", "expectedRevision"]
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/publications": {
      "post": {
        "operationId": "publishDraft",
        "summary": "Queue a new publication or replace an existing project",
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Operation"
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "draftId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "slug": {
                        "type": "string"
                      },
                      "displayName": {
                        "type": "string"
                      }
                    },
                    "required": ["draftId", "slug"]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "draftId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "projectId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "expectedRevision": {
                        "type": "integer",
                        "minimum": 0
                      }
                    },
                    "required": ["draftId", "projectId", "expectedRevision"]
                  }
                ]
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ]
      }
    },
    "/publications/{id}": {
      "get": {
        "operationId": "getPublication",
        "summary": "Read a queued publication and its final outcome",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Operation"
                }
              }
            }
          },
          "default": {
            "description": "API error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    }
  },
  "components": {
    "securitySchemes": {
      "ProjectKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "PageBaton project API key"
      }
    },
    "schemas": {
      "Project": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "displayName": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "state": {
            "enum": ["live", "offline", "trashed"]
          },
          "revision": {
            "type": "integer",
            "minimum": 0
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "shareUrl": {
            "type": "string",
            "format": "uri"
          },
          "frozen": {
            "type": "boolean"
          }
        }
      },
      "Draft": {
        "type": "object",
        "properties": {
          "draftId": {
            "type": "string",
            "format": "uuid"
          },
          "state": {
            "enum": [
              "awaiting_upload",
              "queued",
              "processing",
              "needs_entry",
              "ready",
              "invalid",
              "expired"
            ]
          },
          "revision": {
            "type": "integer",
            "minimum": 0
          },
          "entry": {
            "type": ["string", "null"]
          },
          "candidates": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Operation": {
        "type": "object",
        "properties": {
          "operationId": {
            "type": "string",
            "format": "uuid"
          },
          "state": {
            "enum": ["queued", "running", "succeeded", "failed"]
          },
          "projectId": {
            "type": ["string", "null"]
          },
          "versionId": {
            "type": ["string", "null"]
          },
          "version": {
            "type": ["integer", "null"]
          },
          "shareUrl": {
            "type": "string"
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "requestId": {
            "type": "string"
          }
        }
      }
    }
  }
}
