{
  "openapi": "3.1.0",
  "info": {
    "title": "Formula 1 API",
    "version": "1.0",
    "description": "A Formula 1 testing grid with drivers, constructors, race simulation, lap telemetry and authenticated pit-stop operations."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/formula1/v1"
    }
  ],
  "tags": [
    {
      "name": "grid",
      "description": "drivers and constructors"
    },
    {
      "name": "races",
      "description": "events and results"
    },
    {
      "name": "telemetry",
      "description": "laps and pit stops"
    }
  ],
  "paths": {
    "/drivers": {
      "get": {
        "tags": [
          "grid"
        ],
        "summary": "List drivers by team",
        "operationId": "f1-drivers",
        "responses": {
          "200": {
            "description": "Drivers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "teamId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 2
          }
        ]
      }
    },
    "/constructors": {
      "get": {
        "tags": [
          "grid"
        ],
        "summary": "List constructors with drivers",
        "operationId": "f1-teams",
        "responses": {
          "200": {
            "description": "Constructors",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/races": {
      "get": {
        "tags": [
          "races"
        ],
        "summary": "List races by status",
        "operationId": "f1-races",
        "responses": {
          "200": {
            "description": "Races",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "scheduled"
          }
        ]
      }
    },
    "/races/{id}/start": {
      "post": {
        "tags": [
          "races"
        ],
        "summary": "Run and finish a race",
        "operationId": "f1-race-start",
        "responses": {
          "200": {
            "description": "Race finished",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown race",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Already finished",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "istanbul-2026"
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/races/{id}/results": {
      "get": {
        "tags": [
          "races"
        ],
        "summary": "Get classified race results",
        "operationId": "f1-results",
        "responses": {
          "200": {
            "description": "Results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "409": {
            "description": "Race not finished",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/races/{id}/telemetry": {
      "get": {
        "tags": [
          "telemetry"
        ],
        "summary": "Read lap telemetry after a race",
        "operationId": "f1-telemetry",
        "responses": {
          "200": {
            "description": "Telemetry",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          },
          {
            "name": "afterLap",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 5
          }
        ]
      }
    },
    "/races/{id}/pit-stops": {
      "post": {
        "tags": [
          "telemetry"
        ],
        "summary": "Record a pit stop",
        "operationId": "f1-pitstop",
        "responses": {
          "201": {
            "description": "Pit stop recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "422": {
            "description": "Invalid pit stop",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "driverId": {
                    "type": "integer"
                  },
                  "lap": {
                    "type": "integer"
                  },
                  "durationMs": {
                    "type": "integer"
                  },
                  "compound": {
                    "type": "string"
                  }
                },
                "required": [
                  "driverId",
                  "lap",
                  "durationMs",
                  "compound"
                ],
                "additionalProperties": false
              },
              "example": {
                "driverId": 2,
                "lap": 21,
                "durationMs": 2430,
                "compound": "soft"
              }
            }
          }
        },
        "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
      }
    }
  }
}
