{
  "openapi": "3.1.0",
  "info": {
    "title": "Rivopix Customer API",
    "version": "1.0",
    "summary": "HTTP contract implemented by the company API server for Rivopix iOS.",
    "description": "Rivopix (iOS) is the client. Your server hosts HTTPS endpoints under a configured base URL.\n\n- Health check: fixed relative path `/rivopix/health`\n- Photo upload: relative path from the product QR `_rivopix.path` (company-defined), resolved against the stored connection base URL using Rivopix path-security rules.\n\nThis document describes the **client expectations**. Exact business routes beyond `/rivopix/health` are implemented by each company."
  },
  "servers": [
    {
      "url": "https://api.example.com",
      "description": "Example company base (replace with your HTTPS base)"
    }
  ],
  "tags": [{ "name": "Health" }, { "name": "Upload" }],
  "paths": {
    "/rivopix/health": {
      "get": {
        "tags": ["Health"],
        "operationId": "getRivopixHealth",
        "summary": "Connection health check",
        "description": "Authenticated probe used by Rivopix iOS and the website setup generator. Confirms reachability, protocol identity, API key acceptance, and upload permission.",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Protocol OK. Upload may still be denied via permissions.upload=false.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HealthSuccess" }
              }
            }
          },
          "401": { "description": "Missing or invalid API key" },
          "403": { "description": "Forbidden" },
          "404": { "description": "Health endpoint not found" },
          "429": { "description": "Too many requests" },
          "5XX": { "description": "Server error" }
        }
      },
      "options": {
        "tags": ["Health"],
        "operationId": "optionsRivopixHealth",
        "summary": "CORS preflight (website generator)",
        "description": "Must not require Bearer authentication.",
        "responses": {
          "204": { "description": "No content" }
        }
      }
    },
    "/rivopix/{uploadSegment}": {
      "post": {
        "tags": ["Upload"],
        "operationId": "postRivopixUpload",
        "summary": "Photo upload (example path shape)",
        "description": "Rivopix POSTs multipart/form-data to the absolute HTTPS URL formed from the stored connection base + `_rivopix.path` from the product QR. The `{uploadSegment}` path is illustrative. Real paths are company-defined and must pass Rivopix relative-path security and the connection allow-list (default prefix `/rivopix`).",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "uploadSegment",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": { "type": "string", "format": "uuid" },
            "description": "Stable UUID per upload record; retries reuse the same key."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["image", "payload"],
                "properties": {
                  "image": {
                    "type": "string",
                    "format": "binary",
                    "description": "Photo bytes (JPEG by default; RAW/original when QR allows)."
                  },
                  "payload": {
                    "type": "string",
                    "format": "binary",
                    "description": "UTF-8 JSON of `_rivopix.data` only (not display, not connection secrets)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Rivopix treats any HTTP status in 200–299 as success. Response body is not currently required by the client."
          },
          "401": { "description": "Unauthorized" },
          "4XX": { "description": "Client / validation error (retried with backoff unless permanent)" },
          "5XX": { "description": "Server error (retried with backoff)" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from Setup QR / Keychain. Never place in URLs."
      }
    },
    "schemas": {
      "HealthSuccess": {
        "type": "object",
        "additionalProperties": true,
        "required": ["status", "service", "version", "permissions"],
        "properties": {
          "status": { "type": "string", "const": "ok" },
          "service": { "type": "string", "const": "Rivopix API" },
          "version": { "type": "string", "enum": ["1.0"] },
          "permissions": {
            "type": "object",
            "required": ["upload"],
            "additionalProperties": true,
            "properties": {
              "upload": {
                "type": "boolean",
                "description": "Must be JSON boolean true for a successful connection test."
              }
            }
          }
        }
      }
    }
  }
}
