{
  "openapi": "3.1.0",
  "info": {
    "title": "Powerlifting Live feeds",
    "version": "1.0.0",
    "description": "Public, read-only JSON feeds with live data from a competition. The live screens use the same feeds, so the data is updated as soon as something happens in the competition.\n\n**Request format.** All feeds are read from `feed.php` with `key=competition/{competitionId}/{feed}`. No authentication is needed.\n\n| Feed | key | Response schema |\n|---|---|---|\n| Scoresheet, whole competition | `competition/{competitionId}/scoresheet` | [ScoresheetFeed](schemas/scoresheet.schema.json) |\n| Scoresheet, group on the platform | `competition/{competitionId}/scoresheet/current` | [ScoresheetFeed](schemas/scoresheet.schema.json) |\n| Scoresheet, one group | `competition/{competitionId}/scoresheet/{groupId}` | [ScoresheetFeed](schemas/scoresheet.schema.json) |\n| Lifting order | `competition/{competitionId}/next_lifters` | [NextLiftersFeed](schemas/next-lifters.schema.json) |\n| Lifting order, next group | `competition/{competitionId}/next_lifters_next_group` | [NextGroupLiftersFeed](schemas/next-lifters-next-group.schema.json) |\n| Attempts waiting to be reported | `competition/{competitionId}/raises` | [RaisesFeed](schemas/raises.schema.json) |\n| Competition clock | `competition/{competitionId}/clock` | [ClockFeed](schemas/clock.schema.json) |\n| Last referee decision | `competition/{competitionId}/referee_decision` | [RefereeDecisionFeed](schemas/referee-decision.schema.json) |\n| Team standings | `competition/{competitionId}/team_results` | [TeamResultsFeed](schemas/team-results.schema.json) |\n| Timesheet | `competition/{competitionId}/timesheet` | [TimesheetFeed](schemas/timesheet.schema.json) |\n\nThe competition id is in the competition's page address (`?id=123`). Group ids are in the timesheet feed.\n\n**Empty feeds.** A feed that has not been generated returns `{}`, for example team results when team competition is off.\n\n**Content type.** The body is JSON, but the response is sent as `text/html`. Parse the body as JSON regardless of the header.\n\n**Browsers.** Responses carry `Access-Control-Allow-Origin: *`, so a web page on another domain (or a local file) can read the feeds with `fetch`. `api_competitions.php` lists competitions with weigh-ins from one week back to eight weeks ahead and can be used to pick a competition id.\n\n**Types.** Values read from the database are sent as strings (`\"82.50\"`), values calculated by the server as numbers. Treat numeric fields as either. New fields can be added at any time, so ignore fields you do not know.\n\n**Polling.** Requests are limited to 20 per second per IP address. Poll at most once per second. To receive updates as they happen, subscribe to the topic `competition/{competitionId}/{feed}` with MQTT over WebSocket at `wss://{host}/ws`. Messages contain the same JSON as `feed.php`.\n\n**JSON Schemas.** Each feed is described by a standalone JSON Schema (draft 2020-12), linked in the table. They share the [lifter](schemas/lifter.schema.json) and [common](schemas/common.schema.json) definitions, referenced by relative path.",
    "contact": {
      "name": "Powerlifting Live",
      "url": "https://powerliftinglive.com",
      "email": "odsteen@gmail.com"
    }
  },
  "servers": [
    { "url": "../", "description": "This server" }
  ],
  "tags": [
    { "name": "Feeds", "description": "Live competition data." }
  ],
  "paths": {
    "/feed.php": {
      "get": {
        "tags": ["Feeds"],
        "operationId": "getFeed",
        "summary": "Read a feed",
        "description": "Returns the feed named by `key`. The response schema depends on the feed, see the table in the introduction.",
        "parameters": [
          {
            "name": "key",
            "in": "query",
            "required": true,
            "description": "`competition/{competitionId}/{feed}`. Pick an example and replace the competition id (and group id).",
            "allowReserved": true,
            "schema": {
              "type": "string",
              "pattern": "^competition/[0-9]+/(scoresheet(/(current|[0-9]+))?|next_lifters|next_lifters_next_group|raises|clock|referee_decision|team_results|timesheet)$"
            },
            "examples": {
              "scoresheet": { "summary": "Scoresheet, whole competition", "value": "competition/1/scoresheet" },
              "scoresheetCurrent": { "summary": "Scoresheet, group on the platform", "value": "competition/1/scoresheet/current" },
              "scoresheetGroup": { "summary": "Scoresheet, one group", "value": "competition/1/scoresheet/1" },
              "nextLifters": { "summary": "Lifting order", "value": "competition/1/next_lifters" },
              "nextGroupLifters": { "summary": "Lifting order, next group", "value": "competition/1/next_lifters_next_group" },
              "raises": { "summary": "Attempts waiting to be reported", "value": "competition/1/raises" },
              "clock": { "summary": "Competition clock", "value": "competition/1/clock" },
              "refereeDecision": { "summary": "Last referee decision", "value": "competition/1/referee_decision" },
              "teamResults": { "summary": "Team standings", "value": "competition/1/team_results" },
              "timesheet": { "summary": "Timesheet", "value": "competition/1/timesheet" }
            }
          },
          {
            "name": "expireSeconds",
            "in": "query",
            "required": false,
            "description": "Only for referee_decision: return the decision only if it is newer than this many seconds, otherwise `{}`.",
            "schema": { "type": "integer", "minimum": 0 }
          }
        ],
        "responses": {
          "200": {
            "description": "The feed, or `{}` when it has not been generated.",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    { "$ref": "#/components/schemas/ScoresheetFeed" },
                    { "$ref": "#/components/schemas/NextLiftersFeed" },
                    { "$ref": "#/components/schemas/NextGroupLiftersFeed" },
                    { "$ref": "#/components/schemas/RaisesFeed" },
                    { "$ref": "#/components/schemas/ClockFeed" },
                    { "$ref": "#/components/schemas/RefereeDecisionFeed" },
                    { "$ref": "#/components/schemas/TeamResultsFeed" },
                    { "$ref": "#/components/schemas/TimesheetFeed" },
                    { "$ref": "#/components/schemas/EmptyFeed" }
                  ]
                },
                "examples": {
                  "clock": { "summary": "clock", "value": { "clock": 42 } },
                  "raises": {
                    "summary": "raises",
                    "value": {
                      "raises": [
                        { "lifter_id": "15", "lifter_name": "Kari Nordmann", "lift_name": "SQ2_15", "seconds": 38, "last_lift": 1763887200, "value_default": 152.5 }
                      ]
                    }
                  },
                  "empty": { "summary": "Feed not generated", "value": {} }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ScoresheetFeed": { "$ref": "schemas/scoresheet.schema.json" },
      "NextLiftersFeed": { "$ref": "schemas/next-lifters.schema.json" },
      "NextGroupLiftersFeed": { "$ref": "schemas/next-lifters-next-group.schema.json" },
      "RaisesFeed": { "$ref": "schemas/raises.schema.json" },
      "ClockFeed": { "$ref": "schemas/clock.schema.json" },
      "RefereeDecisionFeed": { "$ref": "schemas/referee-decision.schema.json" },
      "TeamResultsFeed": { "$ref": "schemas/team-results.schema.json" },
      "TimesheetFeed": { "$ref": "schemas/timesheet.schema.json" },
      "Lifter": { "$ref": "schemas/lifter.schema.json" },
      "EmptyFeed": {
        "description": "Returned when the feed has not been generated.",
        "type": "object",
        "maxProperties": 0
      }
    }
  }
}
