{
  "openapi": "3.1.0",
  "info": {
    "title": "Coffee Shop API",
    "version": "1.0",
    "description": "A café counter API: browse drinks, place orders — and GET /teapot, which proudly returns HTTP 418 \"I'm a teapot\"."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/coffee/v1"
    }
  ],
  "tags": [
    {
      "name": "drinks",
      "description": "hot and cold"
    },
    {
      "name": "orders",
      "description": "name on the cup"
    },
    {
      "name": "rush",
      "description": "hammer it and watch the 429s"
    },
    {
      "name": "teapot",
      "description": "RFC 2324 compliance"
    }
  ],
  "paths": {
    "/drinks": {
      "get": {
        "tags": [
          "drinks"
        ],
        "summary": "List drinks, filter by type",
        "operationId": "cf-list",
        "responses": {
          "200": {
            "description": "Drink list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid type",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "required": false,
            "description": "\"hot\" or \"cold\". Anything else → 400.",
            "schema": {
              "type": "string"
            },
            "example": "hot"
          }
        ]
      }
    },
    "/drinks/{id}": {
      "get": {
        "tags": [
          "drinks"
        ],
        "summary": "Get one drink",
        "operationId": "cf-get",
        "responses": {
          "200": {
            "description": "The drink",
            "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": "Drink id 1–8.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 8
          }
        ]
      }
    },
    "/orders": {
      "post": {
        "tags": [
          "orders"
        ],
        "summary": "Order a drink",
        "operationId": "cf-post",
        "responses": {
          "201": {
            "description": "Order placed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "description": "Unknown drinkId or missing name",
            "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": {
                  "drinkId": {
                    "type": "number"
                  },
                  "size": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "drinkId": 2,
                "size": "grande",
                "name": "Rachel"
              }
            }
          }
        }
      }
    },
    "/rush-hour": {
      "get": {
        "tags": [
          "rush"
        ],
        "summary": "Rush hour special — max 3 requests per 10s",
        "operationId": "cf-rush",
        "responses": {
          "200": {
            "description": "Got a spot in line",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "429": {
            "description": "Too many requests — wait for Retry-After seconds",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/teapot": {
      "get": {
        "tags": [
          "teapot"
        ],
        "summary": "Try to brew coffee in a teapot",
        "operationId": "cf-teapot",
        "responses": {
          "418": {
            "description": "Always. It is, in fact, a teapot.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/{id}/ready": {
      "put": {
        "tags": [
          "orders"
        ],
        "summary": "Mark an order ready (409 if already ready)",
        "operationId": "cf-ready",
        "responses": {
          "200": {
            "description": "Marked ready",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Order is already ready",
            "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": "Order id from a prior POST /orders.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 501
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": false,
            "description": "Optimistic concurrency: pass a prior etag (e.g. v1). Mismatch → 412.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    }
  },
  "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
      }
    }
  }
}
