{
  "openapi": "3.1.0",
  "info": {
    "title": "running.services Race API",
    "version": "1.0.0",
    "description": "Read-only race data API. Request an API key at https://running.services/developers. Monthly usage limits apply."
  },
  "servers": [{ "url": "https://running.services" }],
  "security": [{ "ApiKey": [] }],
  "paths": {
    "/api/v1/races": {
      "get": {
        "summary": "Search races",
        "operationId": "listRaces",
        "parameters": [
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/PerPage" },
          { "name": "city", "in": "query", "schema": { "type": "string" } },
          { "name": "state", "in": "query", "schema": { "type": "string" } },
          { "name": "distance", "in": "query", "schema": { "type": "string" } },
          { "name": "surface", "in": "query", "schema": { "type": "string" } },
          { "name": "isTurkeyTrot", "in": "query", "schema": { "type": "boolean" } },
          { "name": "bostonQualifier", "in": "query", "schema": { "type": "boolean" } },
          { "name": "walkerFriendly", "in": "query", "schema": { "type": "boolean" } },
          { "name": "strollerFriendly", "in": "query", "schema": { "type": "boolean" } }
        ],
        "responses": {
          "200": {
            "description": "A page of races",
            "content": { "application/json": { "schema": {
              "type": "object",
              "required": ["page", "perPage", "results"],
              "properties": {
                "page": { "type": "integer" },
                "perPage": { "type": "integer" },
                "results": { "type": "array", "items": { "$ref": "#/components/schemas/Race" } }
              }
            } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/api/v1/races/{slug}": {
      "get": {
        "summary": "Get one race",
        "operationId": "getRace",
        "parameters": [{ "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Race details", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Race" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "description": "Race not found" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/api/v1/featured/races": {
      "get": {
        "summary": "List featured races",
        "operationId": "listFeaturedRaces",
        "parameters": [
          { "name": "cityId", "in": "query", "schema": { "type": "integer" } },
          { "name": "distance", "in": "query", "schema": { "type": "string" } },
          { "name": "isTurkeyTrot", "in": "query", "schema": { "type": "boolean" } }
        ],
        "responses": {
          "200": { "description": "Featured races", "content": { "application/json": { "schema": {
            "type": "object",
            "required": ["results"],
            "properties": { "results": { "type": "array", "items": { "$ref": "#/components/schemas/Race" } } }
          } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": { "type": "apiKey", "in": "header", "name": "X-API-Key", "description": "Request a key at https://running.services/developers" }
    },
    "parameters": {
      "Page": { "name": "page", "in": "query", "schema": { "type": "integer", "minimum": 1, "default": 1 } },
      "PerPage": { "name": "perPage", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 25 } }
    },
    "responses": {
      "Unauthorized": { "description": "Missing, invalid, or revoked API key" },
      "RateLimited": { "description": "Monthly request limit exceeded" }
    },
    "schemas": {
      "Race": {
        "type": "object",
        "required": ["id", "slug", "name", "url", "scores"],
        "properties": {
          "id": { "type": "integer" },
          "slug": { "type": "string" },
          "name": { "type": "string" },
          "date": { "type": ["string", "null"], "description": "Race date when known" },
          "city": { "type": ["string", "null"] },
          "state": { "type": ["string", "null"] },
          "distance": { "type": ["string", "null"] },
          "distanceMeters": { "type": ["number", "null"] },
          "surface": { "type": ["string", "null"] },
          "website": { "type": ["string", "null"] },
          "registrationUrl": { "type": ["string", "null"] },
          "priceMin": { "type": ["number", "null"] },
          "priceMax": { "type": ["number", "null"] },
          "priceCurrency": { "type": "string" },
          "isTurkeyTrot": { "type": "boolean" },
          "bostonQualifier": { "type": "boolean" },
          "walkerFriendly": { "type": "boolean" },
          "strollerFriendly": { "type": "boolean" },
          "scores": { "type": "object", "additionalProperties": { "type": ["integer", "null"] } },
          "organizerId": { "type": ["integer", "null"] },
          "seriesId": { "type": ["integer", "null"] },
          "url": { "type": "string", "format": "uri" }
        },
        "additionalProperties": true
      }
    }
  }
}
