{
  "openapi": "3.1.0",
  "info": {
    "title": "Protocol Lab API",
    "version": "1.0",
    "description": "Protocol mechanics the themed APIs do not cover: 202 Accepted with job polling, 301/302 redirects (and a chain), 503 with Retry-After, a guaranteed 504, Accept-based content negotiation with 406, HATEOAS links, RFC 6902 JSON Patch and 410 Gone."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/protocol/v1"
    }
  ],
  "tags": [
    {
      "name": "jobs",
      "description": "202 Accepted + poll to completion"
    },
    {
      "name": "redirects",
      "description": "301, 302 and a chain to follow"
    },
    {
      "name": "outages",
      "description": "503 & 504 on demand"
    },
    {
      "name": "documents",
      "description": "HATEOAS, JSON Patch, 406 & 410"
    }
  ],
  "paths": {
    "/jobs": {
      "post": {
        "tags": [
          "jobs"
        ],
        "summary": "Start an async job — 202 Accepted",
        "operationId": "pl-job-create",
        "responses": {
          "202": {
            "description": "Accepted. Poll the Location header until status is \"done\".",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Unknown job type",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string"
                  },
                  "pages": {
                    "type": "integer"
                  }
                },
                "required": [
                  "type",
                  "pages"
                ],
                "additionalProperties": false
              },
              "example": {
                "type": "report",
                "pages": 3
              }
            }
          }
        }
      }
    },
    "/jobs/{id}": {
      "get": {
        "tags": [
          "jobs"
        ],
        "summary": "Poll a job — progresses on every poll",
        "operationId": "pl-job-get",
        "responses": {
          "200": {
            "description": "queued → running → done, advancing each time you poll",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Job id from POST /jobs (7001+).",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 7001
          }
        ]
      }
    },
    "/moved/old-dashboard": {
      "get": {
        "tags": [
          "redirects"
        ],
        "summary": "Permanently moved — 301",
        "operationId": "pl-redirect-301",
        "responses": {
          "301": {
            "description": "Always. Follow the Location header — real HTTP clients do it automatically.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/moved/new-dashboard": {
      "get": {
        "tags": [
          "redirects"
        ],
        "summary": "Where the 301 leads",
        "operationId": "pl-redirect-new",
        "responses": {
          "200": {
            "description": "You made it",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/hop": {
      "get": {
        "tags": [
          "redirects"
        ],
        "summary": "A 302 redirect chain — follow it down",
        "operationId": "pl-redirect-chain",
        "responses": {
          "200": {
            "description": "End of the chain (hops ≤ 1)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "302": {
            "description": "Redirects to /hop?hops=n-1",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "hops out of range",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "hops",
            "in": "query",
            "required": false,
            "description": "Chain length 1–5, default 3. Each hop 302-redirects to hops-1 until 1.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 3
          }
        ]
      }
    },
    "/maintenance": {
      "get": {
        "tags": [
          "outages"
        ],
        "summary": "Scheduled maintenance — 503 + Retry-After",
        "operationId": "pl-maintenance",
        "responses": {
          "503": {
            "description": "Always, with a Retry-After header. Good retry/backoff practice.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/gateway-timeout": {
      "get": {
        "tags": [
          "outages"
        ],
        "summary": "Slow upstream — waits ~3s, then 504",
        "operationId": "pl-slow",
        "responses": {
          "504": {
            "description": "Always, after ~3 seconds. Pair it with a 2s client timeout.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/export/documents": {
      "get": {
        "tags": [
          "documents"
        ],
        "summary": "Content negotiation via Accept (406 on anything else)",
        "operationId": "pl-export",
        "responses": {
          "200": {
            "description": "Documents in the negotiated format (see \"contentType\" + \"payload\")",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "406": {
            "description": "Unsupported Accept value",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "description": "application/json (default), text/csv or application/xml. Anything else → 406.",
            "schema": {
              "type": "string"
            },
            "example": "text/csv"
          }
        ]
      }
    },
    "/documents": {
      "get": {
        "tags": [
          "documents"
        ],
        "summary": "List documents (HATEOAS links)",
        "operationId": "pl-docs",
        "responses": {
          "200": {
            "description": "Documents, each carrying _links to discover related actions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/documents/{id}": {
      "get": {
        "tags": [
          "documents"
        ],
        "summary": "Get a document (410 after deletion)",
        "operationId": "pl-doc",
        "responses": {
          "200": {
            "description": "The document with _links and an ETag",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Never existed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Deleted — Gone",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Document id 1–3.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      },
      "patch": {
        "tags": [
          "documents"
        ],
        "summary": "RFC 6902 JSON Patch (op/path/value)",
        "operationId": "pl-patch",
        "responses": {
          "200": {
            "description": "Patched document, version bumped",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Body is not a patch array, or unsupported op/path",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown document",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "A \"test\" operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Document id.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "op": {
                      "type": "string"
                    },
                    "path": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "op",
                    "path",
                    "value"
                  ],
                  "additionalProperties": false
                }
              },
              "example": [
                {
                  "op": "replace",
                  "path": "/title",
                  "value": "Sharper regression checklist"
                },
                {
                  "op": "add",
                  "path": "/tags/-",
                  "value": "patched"
                }
              ]
            }
          }
        }
      },
      "delete": {
        "tags": [
          "documents"
        ],
        "summary": "Delete a document (admin only, then 410)",
        "operationId": "pl-doc-del",
        "responses": {
          "204": {
            "description": "Deleted — subsequent GETs return 410"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Viewer token not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Never existed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Already deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Document id to delete.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 2
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Use qa-admin-token / qa-viewer-token, or a JWT from POST /auth/v1/login."
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Cargo demo key: cargo-key-123."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "requestId": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    }
  }
}
