{
  "openapi": "3.1.0",
  "info": {
    "title": "Football API",
    "version": "1.0",
    "description": "A fictional league: teams with nested player squads, a standings table, and a match simulator with input validation."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/football/v1"
    }
  ],
  "tags": [
    {
      "name": "teams",
      "description": "six fictional clubs"
    },
    {
      "name": "league",
      "description": "standings and matches"
    }
  ],
  "paths": {
    "/teams": {
      "get": {
        "tags": [
          "teams"
        ],
        "summary": "List teams (paginated)",
        "operationId": "fb-teams",
        "responses": {
          "200": {
            "description": "Paginated team list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid page",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Page out of range",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Page number, 4 per page.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/teams/{id}": {
      "get": {
        "tags": [
          "teams"
        ],
        "summary": "Get one team",
        "operationId": "fb-team",
        "responses": {
          "200": {
            "description": "The team",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Team id 1–6.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      },
      "delete": {
        "tags": [
          "teams"
        ],
        "summary": "Remove a team (409 if it has played matches)",
        "operationId": "fb-team-del",
        "responses": {
          "204": {
            "description": "Removed"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Viewer token not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Team has played matches",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "412": {
            "description": "If-Match does not match current version",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Team id. Viewer token → 403.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 5
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": false,
            "description": "Optimistic concurrency check. Mismatch → 412.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/teams/{id}/players": {
      "get": {
        "tags": [
          "teams"
        ],
        "summary": "Get a team's squad (nested)",
        "operationId": "fb-players",
        "responses": {
          "200": {
            "description": "Player list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown team",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Team id 1–6.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 2
          }
        ]
      }
    },
    "/teams/{id}/matches": {
      "get": {
        "tags": [
          "teams"
        ],
        "summary": "Get a team's match history (nested resource)",
        "operationId": "fb-team-matches",
        "responses": {
          "200": {
            "description": "Match list for the team",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown team",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Team id 1–6. Empty until you POST /matches.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/standings": {
      "get": {
        "tags": [
          "league"
        ],
        "summary": "League table — cacheable (ETag / If-None-Match / 304)",
        "operationId": "fb-standings",
        "responses": {
          "200": {
            "description": "Current standings, with ETag + Cache-Control headers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "304": {
            "description": "Not Modified — If-None-Match matched the current etag",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-None-Match",
            "in": "header",
            "required": false,
            "description": "Pass a prior etag; if unchanged, get 304 with no body instead of re-downloading the table.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/matches": {
      "post": {
        "tags": [
          "league"
        ],
        "summary": "Simulate a match",
        "operationId": "fb-match",
        "responses": {
          "201": {
            "description": "Match played, random score",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "description": "Same team twice or unknown team",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Repeat the same key on retry to get the original response instead of a duplicate.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "homeTeamId": {
                    "type": "integer"
                  },
                  "awayTeamId": {
                    "type": "integer"
                  }
                },
                "required": [
                  "homeTeamId",
                  "awayTeamId"
                ],
                "additionalProperties": false
              },
              "example": {
                "homeTeamId": 1,
                "awayTeamId": 2
              }
            }
          }
        },
        "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
      }
    }
  }
}
