{
  "openapi": "3.1.0",
  "info": {
    "title": "Weather API",
    "version": "1.0",
    "description": "A no-key weather API for tutorials and tests: current conditions, daily and hourly forecasts in US or metric units, state alerts, and outage, timeout and stale-data scenarios. Values are synthetic and deterministic, never real observations."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/weather/v1"
    }
  ],
  "tags": [
    {
      "name": "locations",
      "description": "supported places"
    },
    {
      "name": "weather",
      "description": "current and forecast"
    },
    {
      "name": "alerts",
      "description": "state alerts"
    }
  ],
  "paths": {
    "/locations": {
      "get": {
        "tags": [
          "locations"
        ],
        "summary": "Supported locations with coordinates and time zones",
        "operationId": "wx-locations",
        "responses": {
          "200": {
            "description": "Locations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "latitude": {
                            "type": "number"
                          },
                          "longitude": {
                            "type": "number"
                          },
                          "timeZone": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Global rate limit exceeded (300 requests a minute per IP) — wait for Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/current": {
      "get": {
        "tags": [
          "weather"
        ],
        "summary": "Current conditions (deterministic per location and hour)",
        "operationId": "wx-current",
        "responses": {
          "200": {
            "description": "Conditions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "location": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "latitude": {
                          "type": "number"
                        },
                        "longitude": {
                          "type": "number"
                        },
                        "timeZone": {
                          "type": "string"
                        }
                      }
                    },
                    "observedAt": {
                      "type": "string"
                    },
                    "condition": {
                      "type": "string"
                    },
                    "temperature": {
                      "type": "number"
                    },
                    "temperatureUnit": {
                      "type": "string"
                    },
                    "wind": {
                      "type": "number"
                    },
                    "windUnit": {
                      "type": "string"
                    },
                    "humidity": {
                      "type": "number"
                    },
                    "units": {
                      "type": "string"
                    },
                    "stale": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid parameter",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown location",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Global rate limit exceeded (300 requests a minute per IP) — wait for Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "scenario=outage",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "504": {
            "description": "scenario=timeout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "location",
            "in": "query",
            "required": true,
            "description": "Location id from /locations",
            "schema": {
              "type": "string"
            },
            "example": "austin"
          },
          {
            "name": "units",
            "in": "query",
            "required": false,
            "description": "us (°F, mph, in — default) or si (°C, km/h, mm)",
            "schema": {
              "type": "string"
            },
            "example": "us"
          },
          {
            "name": "scenario",
            "in": "query",
            "required": false,
            "description": "outage → 503 + Retry-After, timeout → 504 after 6 s, stale → 200 with a Warning header",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/forecast": {
      "get": {
        "tags": [
          "weather"
        ],
        "summary": "Daily forecast, 1–7 days",
        "operationId": "wx-forecast",
        "responses": {
          "200": {
            "description": "Forecast",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "location": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "latitude": {
                          "type": "number"
                        },
                        "longitude": {
                          "type": "number"
                        },
                        "timeZone": {
                          "type": "string"
                        }
                      }
                    },
                    "units": {
                      "type": "string"
                    },
                    "generatedAt": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string"
                          },
                          "condition": {
                            "type": "string"
                          },
                          "high": {
                            "type": "number"
                          },
                          "low": {
                            "type": "number"
                          },
                          "temperatureUnit": {
                            "type": "string"
                          },
                          "precipitationChance": {
                            "type": "number"
                          },
                          "precipitation": {
                            "type": "number"
                          },
                          "precipitationUnit": {
                            "type": "string"
                          },
                          "wind": {
                            "type": "number"
                          },
                          "windUnit": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid days or units",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown location",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Global rate limit exceeded (300 requests a minute per IP) — wait for Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "scenario=outage",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "504": {
            "description": "scenario=timeout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "location",
            "in": "query",
            "required": true,
            "description": "Location id from /locations",
            "schema": {
              "type": "string"
            },
            "example": "austin"
          },
          {
            "name": "days",
            "in": "query",
            "required": false,
            "description": "1–7, default 3",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 3
          },
          {
            "name": "units",
            "in": "query",
            "required": false,
            "description": "us (°F, mph, in — default) or si (°C, km/h, mm)",
            "schema": {
              "type": "string"
            },
            "example": "us"
          },
          {
            "name": "scenario",
            "in": "query",
            "required": false,
            "description": "outage → 503 + Retry-After, timeout → 504 after 6 s, stale → 200 with a Warning header",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/hourly": {
      "get": {
        "tags": [
          "weather"
        ],
        "summary": "Hourly temperatures, 1–48 hours",
        "operationId": "wx-hourly",
        "responses": {
          "200": {
            "description": "Hourly series",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "location": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "latitude": {
                          "type": "number"
                        },
                        "longitude": {
                          "type": "number"
                        },
                        "timeZone": {
                          "type": "string"
                        }
                      }
                    },
                    "units": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "time": {
                            "type": "string"
                          },
                          "temperature": {
                            "type": "number"
                          },
                          "temperatureUnit": {
                            "type": "string"
                          },
                          "condition": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid hours",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown location",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Global rate limit exceeded (300 requests a minute per IP) — wait for Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "location",
            "in": "query",
            "required": true,
            "description": "Location id from /locations",
            "schema": {
              "type": "string"
            },
            "example": "austin"
          },
          {
            "name": "hours",
            "in": "query",
            "required": false,
            "description": "1–48, default 12",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 6
          },
          {
            "name": "units",
            "in": "query",
            "required": false,
            "description": "us (°F, mph, in — default) or si (°C, km/h, mm)",
            "schema": {
              "type": "string"
            },
            "example": "us"
          }
        ]
      }
    },
    "/alerts": {
      "get": {
        "tags": [
          "alerts"
        ],
        "summary": "Active alerts for a US state (may be an empty list)",
        "operationId": "wx-alerts",
        "responses": {
          "200": {
            "description": "Alerts (possibly none)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "state": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array"
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Global rate limit exceeded (300 requests a minute per IP) — wait for Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": true,
            "description": "Two-letter US state, e.g. TX",
            "schema": {
              "type": "string"
            },
            "example": "TX"
          }
        ]
      }
    }
  },
  "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
      }
    }
  }
}
