{
  "openapi": "3.0.3",
  "info": {
    "title": "PJ.SEC Portfolio API",
    "description": "Five REST endpoints with distinct schema validation rules for Cloudflare API Shield testing.",
    "version": "2.0.0",
    "contact": { "name": "Pasindu Jayawardane", "email": "contact@picklerobot.store" }
  },
  "servers": [{ "url": "https://picklerobot.store", "description": "Production (Cloudflare)" }],
  "paths": {
    "/api/profile": {
      "get": {
        "operationId": "getProfile",
        "summary": "Get profile",
        "description": "Schema: optional query param 'format' must be enum [json, yaml].",
        "tags": ["Profile"],
        "parameters": [
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["json", "yaml"] },
            "description": "Response format — must be json or yaml"
          }
        ],
        "responses": {
          "200": { "description": "Profile data returned" },
          "400": { "description": "Invalid format value" }
        }
      }
    },
    "/api/search": {
      "get": {
        "operationId": "searchContent",
        "summary": "Search content",
        "description": "Schema: 'q' is required (minLength:2, maxLength:50). 'category' optional enum.",
        "tags": ["Search"],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": { "type": "string", "minLength": 2, "maxLength": 50 },
            "description": "Search query — required, min 2 characters"
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["all", "projects", "skills", "certs"] },
            "description": "Filter category"
          }
        ],
        "responses": {
          "200": { "description": "Search results" },
          "400": { "description": "Missing or invalid params" }
        }
      }
    },
    "/api/contact": {
      "post": {
        "operationId": "submitContact",
        "summary": "Submit contact message",
        "description": "Schema: POST body requires name, email (format:email), subject (min 5), message (min 10).",
        "tags": ["Contact"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "email", "subject", "message"],
                "properties": {
                  "name":    { "type": "string", "minLength": 2,  "maxLength": 80 },
                  "email":   { "type": "string", "format": "email" },
                  "subject": { "type": "string", "minLength": 5,  "maxLength": 120 },
                  "message": { "type": "string", "minLength": 10, "maxLength": 2000 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Message received" },
          "422": { "description": "Schema violation" }
        }
      }
    },
    "/api/scan": {
      "post": {
        "operationId": "runScan",
        "summary": "Run network scan",
        "description": "Schema: 'target' must be IPv4 or domain pattern. 'type' enum [port,dns,ping,http]. 'options' nested object.",
        "tags": ["Scan"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["target", "type"],
                "properties": {
                  "target": {
                    "type": "string",
                    "pattern": "^(\\d{1,3}\\.){3}\\d{1,3}$|^[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z]{2,})+$"
                  },
                  "type": { "type": "string", "enum": ["port", "dns", "ping", "http"] },
                  "options": {
                    "type": "object",
                    "properties": {
                      "timeout": { "type": "integer", "minimum": 1, "maximum": 30 },
                      "ports":   { "type": "array", "items": { "type": "integer", "minimum": 1, "maximum": 65535 }, "maxItems": 20 }
                    },
                    "additionalProperties": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Scan results" },
          "422": { "description": "Schema violation" }
        }
      }
    },
    "/api/auth/token": {
      "post": {
        "operationId": "getAuthToken",
        "summary": "Get auth token",
        "description": "Schema: Authorization: Bearer header required (min 32 chars). Body: client_id pattern, grant_type enum, scope enum, optional expires_in range.",
        "tags": ["Auth"],
        "security": [{ "BearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["client_id", "grant_type", "scope"],
                "properties": {
                  "client_id":  { "type": "string", "pattern": "^[a-z0-9_]{4,32}$" },
                  "grant_type": { "type": "string", "enum": ["client_credentials", "api_key"] },
                  "scope":      { "type": "string", "enum": ["read", "write", "admin"] },
                  "expires_in": { "type": "integer", "minimum": 300, "maximum": 86400 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Token issued" },
          "401": { "description": "Auth or schema violation" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": { "type": "http", "scheme": "bearer", "description": "API key — minimum 32 characters" }
    }
  }
}
