{
  "openapi": "3.1.0",
  "info": {
    "title": "Pizza Orders API",
    "version": "1.0",
    "description": "A tiny pizzeria backend: menu, order placement with validation, an order-status flow — and /oven/status, which always returns 500 for negative testing."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/pizza/v1"
    }
  ],
  "tags": [
    {
      "name": "menu",
      "description": "six pizzas, one controversial"
    },
    {
      "name": "orders",
      "description": "received → baking → out-for-delivery → delivered"
    },
    {
      "name": "oven",
      "description": "do not trust the oven"
    }
  ],
  "paths": {
    "/menu": {
      "delete": {
        "tags": [
          "menu"
        ],
        "summary": "Delete the menu — always 405, the menu is read-only",
        "operationId": "pz-menu-del",
        "responses": {
          "405": {
            "description": "Always. GET is the only supported method on /menu.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "menu"
        ],
        "summary": "Get the menu",
        "operationId": "pz-menu",
        "responses": {
          "200": {
            "description": "The menu",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid vegetarian value",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "vegetarian",
            "in": "query",
            "required": false,
            "description": "true / false to filter. Anything else → 400.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/orders": {
      "post": {
        "tags": [
          "orders"
        ],
        "summary": "Place an order (validated)",
        "operationId": "pz-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 pizzaId, bad size, or missing address",
            "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": {
                  "pizzaId": {
                    "type": "integer"
                  },
                  "size": {
                    "type": "string"
                  },
                  "address": {
                    "type": "string"
                  }
                },
                "required": [
                  "pizzaId",
                  "size",
                  "address"
                ],
                "additionalProperties": false
              },
              "example": {
                "pizzaId": 3,
                "size": "L",
                "address": "Central Perk, New York"
              }
            }
          }
        }
      }
    },
    "/orders/{id}": {
      "get": {
        "tags": [
          "orders"
        ],
        "summary": "Track an order",
        "operationId": "pz-get",
        "responses": {
          "200": {
            "description": "The order",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Try 101 or 102 (seeded), or your own from POST /orders.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 101
          }
        ]
      },
      "patch": {
        "tags": [
          "orders"
        ],
        "summary": "Partially update an order (address or size)",
        "operationId": "pz-patch",
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Empty body, invalid JSON, or bad size",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Order id.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 101
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "address": {
                    "type": "string"
                  }
                },
                "required": [
                  "address"
                ],
                "additionalProperties": false
              },
              "example": {
                "address": "90 Bedford St, New York, Apt 2"
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "orders"
        ],
        "summary": "Cancel an order (409 if already delivered)",
        "operationId": "pz-cancel",
        "responses": {
          "204": {
            "description": "Cancelled"
          },
          "404": {
            "description": "Unknown order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Order already delivered — cannot cancel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Order id. Try 101 (seeded, delivered) for a 409.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 102
          }
        ]
      }
    },
    "/orders/{id}/status": {
      "put": {
        "tags": [
          "orders"
        ],
        "summary": "Update order status",
        "operationId": "pz-put",
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid status value",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown order",
            "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.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 102
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": false,
            "description": "Optimistic concurrency: pass a prior etag (e.g. v1). Mismatch → 412.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string"
                  }
                },
                "required": [
                  "status"
                ],
                "additionalProperties": false
              },
              "example": {
                "status": "out-for-delivery"
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/oven/status": {
      "get": {
        "tags": [
          "oven"
        ],
        "summary": "Always returns 500 — for negative tests",
        "operationId": "pz-oven",
        "responses": {
          "500": {
            "description": "Always. The oven is on fire.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/oven/preheat": {
      "get": {
        "tags": [
          "oven"
        ],
        "summary": "Preheat the oven — always takes ~3s",
        "operationId": "pz-preheat",
        "responses": {
          "200": {
            "description": "Preheated, after a deliberate ~3s delay",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    }
  },
  "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
      }
    }
  }
}
