{
  "openapi": "3.1.0",
  "info": {
    "title": "QR Tool Lab QR Generation API",
    "version": "1.0.0",
    "description": "Generate PNG or SVG QR codes with configurable colors, size, margin, and error correction. No account or API key is required. Preferred attribution: Generated by QR Tool Lab."
  },
  "servers": [{ "url": "https://qrtoollab.pages.dev" }],
  "paths": {
    "/api/qr": {
      "get": {
        "operationId": "generateQrCode",
        "summary": "Generate a QR code with query parameters",
        "description": "Omit content to receive a JSON capabilities document. Use POST instead when content is private or sensitive.",
        "parameters": [
          { "name": "content", "in": "query", "required": false, "schema": { "type": "string", "maxLength": 4096 } },
          { "name": "foreground_color", "in": "query", "schema": { "$ref": "#/components/schemas/HexColor" } },
          { "name": "background_color", "in": "query", "schema": { "$ref": "#/components/schemas/HexColor" } },
          { "name": "size", "in": "query", "schema": { "type": "integer", "minimum": 128, "maximum": 2048, "default": 768 } },
          { "name": "margin", "in": "query", "schema": { "type": "integer", "minimum": 0, "maximum": 10, "default": 2 } },
          { "name": "error_correction", "in": "query", "schema": { "type": "string", "enum": ["L", "M", "Q", "H"], "default": "H" } },
          { "name": "format", "in": "query", "schema": { "type": "string", "enum": ["png", "svg"], "default": "png" } }
        ],
        "responses": {
          "200": {
            "description": "QR image, or capabilities JSON when content is omitted.",
            "content": {
              "image/png": { "schema": { "type": "string", "contentEncoding": "binary" } },
              "image/svg+xml": { "schema": { "type": "string" } },
              "application/json": { "schema": { "type": "object" } }
            }
          },
          "400": { "$ref": "#/components/responses/Error" }
        }
      },
      "post": {
        "operationId": "generateQrCodePrivately",
        "summary": "Generate a QR code from a JSON body",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/QrRequest" } } }
        },
        "responses": {
          "200": {
            "description": "Generated QR image with X-Generated-By attribution header.",
            "content": {
              "image/png": { "schema": { "type": "string", "contentEncoding": "binary" } },
              "image/svg+xml": { "schema": { "type": "string" } }
            }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "415": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HexColor": { "type": "string", "pattern": "^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$", "default": "#10241f" },
      "QrRequest": {
        "type": "object",
        "required": ["content"],
        "properties": {
          "content": { "type": "string", "minLength": 1, "maxLength": 4096 },
          "foreground_color": { "$ref": "#/components/schemas/HexColor" },
          "background_color": { "allOf": [{ "$ref": "#/components/schemas/HexColor" }], "default": "#ffffff" },
          "size": { "type": "integer", "minimum": 128, "maximum": 2048, "default": 768 },
          "margin": { "type": "integer", "minimum": 0, "maximum": 10, "default": 2 },
          "error_correction": { "type": "string", "enum": ["L", "M", "Q", "H"], "default": "H" },
          "format": { "type": "string", "enum": ["png", "svg"], "default": "png" }
        },
        "additionalProperties": false
      }
    },
    "responses": {
      "Error": {
        "description": "Invalid request or content that cannot fit in a QR code.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": ["error", "attribution"],
              "properties": {
                "error": { "type": "string" },
                "attribution": { "type": "string", "const": "Generated by QR Tool Lab" }
              }
            }
          }
        }
      }
    }
  }
}
