{
  "openapi": "3.1.0",
  "info": {
    "title": "Vlooienkrabber API",
    "version": "1.0.0",
    "description": "Complete replacement of weekly flea-market data within 40 km of Tilburg."
  },
  "servers": [
    {
      "url": "https://vlooienkrabber.itcleric.com"
    }
  ],
  "paths": {
    "/api/markets.php": {
      "get": {
        "operationId": "getWeeklyMarkets",
        "summary": "Read current-week public markets",
        "security": [],
        "responses": {
          "200": {
            "description": "Current week and markets",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "week_start": {
                      "type": "string"
                    },
                    "week_end": {
                      "type": "string"
                    },
                    "updated_at": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "stale": {
                      "type": "boolean"
                    },
                    "markets": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Market"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "replaceWeeklyMarkets",
        "summary": "Replace ALL existing markets after validation",
        "description": "Send the complete selection in a single request. On any validation error nothing changes. Only the current calendar week is allowed.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "x-openai-isConsequential": true,
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Upload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Entire dataset replaced atomically"
          },
          "400": {
            "description": "Invalid JSON"
          },
          "401": {
            "description": "Missing or invalid Bearer token"
          },
          "413": {
            "description": "Body exceeds 1 MB"
          },
          "415": {
            "description": "Use application/json"
          },
          "422": {
            "description": "Validation failed; existing data unchanged"
          },
          "500": {
            "description": "Storage error"
          },
          "503": {
            "description": "Not configured"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Market": {
        "type": "object",
        "required": [
          "id",
          "title",
          "description",
          "date",
          "location",
          "address",
          "city",
          "latitude",
          "longitude",
          "url"
        ],
        "properties": {
          "id": {
            "type": "string",
            "maxLength": 80
          },
          "title": {
            "type": "string",
            "maxLength": 160
          },
          "description": {
            "type": "string",
            "maxLength": 1600
          },
          "location": {
            "type": "string",
            "maxLength": 200
          },
          "address": {
            "type": "string",
            "maxLength": 250
          },
          "city": {
            "type": "string",
            "maxLength": 100
          },
          "price": {
            "type": "string",
            "maxLength": 100
          },
          "date": {
            "type": "string",
            "format": "date"
          },
          "start_time": {
            "type": "string",
            "description": "HH:mm or empty when unknown"
          },
          "end_time": {
            "type": "string",
            "description": "HH:mm or empty when unknown"
          },
          "latitude": {
            "type": "number",
            "minimum": -90,
            "maximum": 90
          },
          "longitude": {
            "type": "number",
            "minimum": -180,
            "maximum": 180
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Public HTTPS event source"
          },
          "category": {
            "type": "string",
            "enum": [
              "Rommelmarkt",
              "Vlooienmarkt",
              "Brocante",
              "Boekenmarkt",
              "Kofferbakmarkt",
              "Vintage"
            ]
          },
          "image_url": {
            "type": "string",
            "description": "HTTPS image or /assets/market-hall.webp, /assets/vintage-stall.webp, /assets/books.webp"
          },
          "image_is_illustrative": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "Upload": {
        "type": "object",
        "required": [
          "week_start",
          "markets"
        ],
        "properties": {
          "week_start": {
            "type": "string",
            "format": "date",
            "description": "Monday of CURRENT calendar week in Europe/Amsterdam"
          },
          "markets": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "$ref": "#/components/schemas/Market"
            }
          },
          "confirm_empty": {
            "type": "boolean",
            "description": "Must be true to explicitly clear all records with an empty list"
          }
        }
      }
    }
  }
}