{
  "openapi": "3.1.0",
  "info": {
    "title": "Event Streams API",
    "version": "1.0",
    "description": "Practice event-stream consumers, Last-Event-ID resume behavior, duplicates and out-of-order detection."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/streams/v1"
    }
  ],
  "tags": [
    {
      "name": "events",
      "description": "stream and replay"
    }
  ],
  "paths": {
    "/events": {
      "get": {
        "tags": [
          "events"
        ],
        "summary": "Read events as JSON or text/event-stream",
        "operationId": "es-events",
        "responses": {
          "200": {
            "description": "JSON batch or SSE stream",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Last-Event-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "5"
          }
        ]
      },
      "post": {
        "tags": [
          "events"
        ],
        "summary": "Publish a custom event",
        "operationId": "es-publish",
        "responses": {
          "202": {
            "description": "Event accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "buildId": {
                        "type": "integer"
                      }
                    },
                    "required": [
                      "buildId"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "type",
                  "data"
                ],
                "additionalProperties": false
              },
              "example": {
                "type": "build.completed",
                "data": {
                  "buildId": 42
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/events/{id}": {
      "get": {
        "tags": [
          "events"
        ],
        "summary": "Replay one event by id",
        "operationId": "es-replay",
        "responses": {
          "200": {
            "description": "Event",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Missing event",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 3
          }
        ]
      }
    }
  },
  "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
      }
    }
  }
}
