{
  "openapi": "3.1.0",
  "info": {
    "title": "IMRC Live API",
    "version": "1.1.0",
    "description": "Public RC racing data for IMRC Setup Manager. Read operations need no authentication. Authoritative publishing from IMRC Race Control uses per-track upload keys. Poll no faster than 10 seconds."
  },
  "servers": [
    {
      "url": "https://live.shopimrc.com/api/v1"
    }
  ],
  "paths": {
    "/tracks": {
      "get": {
        "summary": "List Track",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000000,
              "default": 0
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public data",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Track"
                          }
                        },
                        "nextOffset": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "items",
                        "nextOffset"
                      ]
                    }
                  },
                  "required": [
                    "apiVersion",
                    "data"
                  ]
                }
              }
            }
          },
          "304": {
            "description": "Unchanged; no body"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tracks/{trackId}": {
      "get": {
        "summary": "Read Track",
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public data",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "data": {
                      "$ref": "#/components/schemas/Track"
                    }
                  },
                  "required": [
                    "apiVersion",
                    "data"
                  ]
                }
              }
            }
          },
          "304": {
            "description": "Unchanged; no body"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tracks/{trackId}/live": {
      "get": {
        "summary": "Read Live",
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public data",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "data": {
                      "$ref": "#/components/schemas/Live"
                    }
                  },
                  "required": [
                    "apiVersion",
                    "data"
                  ]
                }
              }
            }
          },
          "304": {
            "description": "Unchanged; no body"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tracks/{trackId}/events": {
      "get": {
        "summary": "List EventSummary",
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000000,
              "default": 0
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public data",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/EventSummary"
                          }
                        },
                        "nextOffset": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "items",
                        "nextOffset"
                      ]
                    }
                  },
                  "required": [
                    "apiVersion",
                    "data"
                  ]
                }
              }
            }
          },
          "304": {
            "description": "Unchanged; no body"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tracks/{trackId}/events/{eventId}": {
      "get": {
        "summary": "Read Event",
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "eventId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "round",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "classId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public data",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "data": {
                      "$ref": "#/components/schemas/Event"
                    }
                  },
                  "required": [
                    "apiVersion",
                    "data"
                  ]
                }
              }
            }
          },
          "304": {
            "description": "Unchanged; no body"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tracks/{trackId}/events/{eventId}/races/{raceId}": {
      "get": {
        "summary": "Read Race",
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "eventId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "raceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public data",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "data": {
                      "$ref": "#/components/schemas/Race"
                    }
                  },
                  "required": [
                    "apiVersion",
                    "data"
                  ]
                }
              }
            }
          },
          "304": {
            "description": "Unchanged; no body"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tracks/{trackId}/series": {
      "get": {
        "summary": "List SeriesSummary",
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000000,
              "default": 0
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public data",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/SeriesSummary"
                          }
                        },
                        "nextOffset": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "items",
                        "nextOffset"
                      ]
                    }
                  },
                  "required": [
                    "apiVersion",
                    "data"
                  ]
                }
              }
            }
          },
          "304": {
            "description": "Unchanged; no body"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tracks/{trackId}/series/{seriesId}": {
      "get": {
        "summary": "Read Series",
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "seriesId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public data",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "apiVersion": {
                      "const": 1
                    },
                    "data": {
                      "$ref": "#/components/schemas/Series"
                    }
                  },
                  "required": [
                    "apiVersion",
                    "data"
                  ]
                }
              }
            }
          },
          "304": {
            "description": "Unchanged; no body"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/tracks/{trackId}/connection": {
      "post": {
        "summary": "Test track connection",
        "description": "HTTPS; per-track key. Snapshot maximum 2 MB and 50 total records; upserts by ID, no deletion. Timestamp must not precede the latest accepted publication. Same-origin browser requests only.",
        "security": [
          {
            "TrackUploadKey": []
          }
        ],
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "localTrackId": {
                    "type": "string"
                  }
                },
                "required": [
                  "localTrackId"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted"
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid upload key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Cross-origin write denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Track identity or stale snapshot conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tracks/{trackId}/snapshot": {
      "post": {
        "summary": "Publish snapshots",
        "description": "HTTPS; per-track key. Snapshot maximum 2 MB and 50 total records; upserts by ID, no deletion. Timestamp must not precede the latest accepted publication. Same-origin browser requests only.",
        "security": [
          {
            "TrackUploadKey": []
          }
        ],
        "parameters": [
          {
            "name": "trackId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Snapshot"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted"
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid upload key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Cross-origin write denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Track identity or stale snapshot conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Payload too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/register": {
      "servers": [
        {
          "url": "https://live.shopimrc.com/api"
        }
      ],
      "post": {
        "summary": "Register a new desktop track without user sign-in",
        "description": "Generate and securely persist a 32-byte random hexadecimal key before the first request. Send it as Bearer authorization and reuse it for retries and publishing. Existing registrations require the same key; no profile edits or key rotation are permitted here. Only IMRC may restore deleted UUIDs.",
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Bearer followed by the privately persisted registration key"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "uuid",
                  "name",
                  "location",
                  "surface"
                ],
                "properties": {
                  "uuid": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "location": {
                    "type": "string",
                    "maxLength": 160
                  },
                  "surface": {
                    "type": "string",
                    "maxLength": 80
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Registered or existing matching key; data contains id, name and registered:true"
          },
          "400": {
            "description": "Invalid input"
          },
          "403": {
            "description": "Cross-origin write rejected"
          },
          "409": {
            "description": "Existing UUID uses another key"
          },
          "410": {
            "description": "UUID deleted by administrator"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "TrackUploadKey": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Driver": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 160
          },
          "position": {
            "type": "integer",
            "minimum": 0
          },
          "carNumber": {
            "type": "integer",
            "minimum": 0
          },
          "laps": {
            "type": "integer",
            "minimum": 0
          },
          "time": {
            "type": "string"
          },
          "best": {
            "type": "string"
          },
          "lastLap": {
            "type": "string"
          },
          "gap": {
            "type": "string"
          },
          "finished": {
            "type": "boolean"
          },
          "lapTimes": {
            "type": "array",
            "items": {
              "type": "number",
              "minimum": 0
            },
            "maxItems": 20000
          }
        },
        "required": [
          "name",
          "position",
          "laps",
          "time"
        ]
      },
      "Race": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "number": {
            "type": "integer",
            "minimum": 0
          },
          "round": {
            "type": "string"
          },
          "classId": {
            "type": "string"
          },
          "className": {
            "type": "string"
          },
          "heat": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "planned",
              "live",
              "completed",
              "skipped"
            ]
          },
          "drivers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Driver"
            },
            "maxItems": 30
          }
        },
        "required": [
          "id",
          "number",
          "round",
          "className",
          "heat",
          "status",
          "drivers"
        ]
      },
      "Event": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "date": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "upcoming",
              "active",
              "completed"
            ]
          },
          "races": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Race"
            },
            "maxItems": 2000
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "date",
          "status",
          "races"
        ]
      },
      "SeriesDriver": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "position": {
            "type": "integer",
            "minimum": 0
          },
          "total": {
            "type": "number"
          },
          "manualPoints": {
            "type": "number"
          },
          "points": {
            "type": "array",
            "items": {
              "type": [
                "number",
                "null"
              ]
            },
            "maxItems": 1000
          },
          "counted": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0
            },
            "maxItems": 1000
          },
          "notes": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 4000
            },
            "maxItems": 1000
          }
        },
        "required": [
          "name",
          "points"
        ]
      },
      "Series": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "className": {
            "type": "string"
          },
          "classId": {
            "type": "string"
          },
          "bestOf": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000
          },
          "weeks": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 1000
          },
          "eventIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 1000
          },
          "authoritative": {
            "type": "boolean",
            "description": "When true, each driver must provide position, total and counted indexes from Race Control."
          },
          "drivers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SeriesDriver"
            },
            "maxItems": 5000
          }
        },
        "required": [
          "id",
          "name",
          "className",
          "bestOf",
          "weeks",
          "drivers"
        ]
      },
      "Track": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "location": {
            "type": "string"
          },
          "surface": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "currentEventId": {
            "type": [
              "string",
              "null"
            ]
          },
          "lastReceivedAt": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "name",
          "location",
          "surface",
          "updatedAt"
        ]
      },
      "Snapshot": {
        "type": "object",
        "properties": {
          "schemaVersion": {
            "type": "integer",
            "const": 1
          },
          "localTrackId": {
            "type": "string",
            "pattern": "^[a-fA-F0-9-]{32,36}$"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "currentEventId": {
            "type": [
              "string",
              "null"
            ]
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Event"
            },
            "maxItems": 100
          },
          "series": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Series"
            },
            "maxItems": 100
          }
        },
        "required": [
          "schemaVersion",
          "localTrackId",
          "generatedAt",
          "currentEventId"
        ]
      },
      "Live": {
        "type": "object",
        "properties": {
          "track": {
            "$ref": "#/components/schemas/Track"
          },
          "event": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Event"
              },
              {
                "type": "null"
              }
            ]
          },
          "races": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Race"
            }
          },
          "generatedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "receivedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "stale": {
            "type": "boolean"
          },
          "pollAfterSeconds": {
            "type": "integer"
          }
        },
        "required": [
          "track",
          "event",
          "races",
          "stale",
          "pollAfterSeconds"
        ]
      },
      "EventSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "date": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "raceCount": {
            "type": "integer"
          },
          "updatedAt": {
            "type": "string"
          }
        }
      },
      "SeriesSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "classId": {
            "type": "string"
          },
          "className": {
            "type": "string"
          },
          "bestOf": {
            "type": "integer"
          },
          "updatedAt": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "apiVersion": {
            "type": "integer",
            "const": 1
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "apiVersion",
          "error"
        ]
      }
    }
  }
}
