{
  "openapi": "3.1.0",
  "info": {
    "title": "Doctosan Directory API",
    "version": "1.1.0",
    "description": "Read-only access to published Doctosan doctor and clinic records. whatsappEligible is a technical reachability signal, not consent or marketing permission."
  },
  "servers": [{ "url": "https://www.doctosan.com" }],
  "security": [{ "ApiKey": [] }],
  "paths": {
    "/api/v1/key": {
      "get": {
        "operationId": "getCurrentDeveloperKey",
        "summary": "Validate the current API key",
        "responses": {
          "200": {
            "description": "Non-secret key metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["key"],
                  "properties": {
                    "key": { "$ref": "#/components/schemas/Key" }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/TooManyRequests" }
        }
      }
    },
    "/api/v1/doctors": {
      "get": {
        "operationId": "searchDoctors",
        "summary": "Search published doctors and clinics",
        "parameters": [
          {
            "name": "country",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["de", "es", "fr", "gb", "it", "mx", "pt"]
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": { "type": "string", "maxLength": 100 }
          },
          {
            "name": "whatsapp",
            "in": "query",
            "schema": { "type": "boolean" }
          },
          {
            "name": "verified",
            "in": "query",
            "schema": { "type": "boolean" }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": { "type": "string", "maxLength": 2048 }
          }
        ],
        "responses": {
          "200": {
            "description": "A bounded page of published records",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DoctorPage" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/TooManyRequests" }
        }
      }
    },
    "/api/v1/doctors/{doctorId}": {
      "get": {
        "operationId": "getDoctor",
        "summary": "Get one current published record",
        "parameters": [
          {
            "name": "doctorId",
            "in": "path",
            "required": true,
            "description": "Stable doctor id or a URL-encoded complete canonical https://www.doctosan.com profile URL in any supported page language.",
            "schema": { "type": "string", "maxLength": 2048 }
          }
        ],
        "responses": {
          "200": {
            "description": "The published record",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["doctor"],
                  "properties": {
                    "doctor": { "$ref": "#/components/schemas/Doctor" }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/TooManyRequests" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": { "type": "apiKey", "in": "header", "name": "X-API-Key" }
    },
    "responses": {
      "BadRequest": { "description": "Invalid query or path parameter" },
      "Unauthorized": { "description": "Missing, invalid, or revoked API key" },
      "NotFound": { "description": "No current published record has that id" },
      "TooManyRequests": { "description": "Per-key rate limit exceeded" }
    },
    "schemas": {
      "Key": {
        "type": "object",
        "required": ["id", "name", "prefix", "creationTime"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "prefix": { "type": "string" },
          "creationTime": { "type": "string", "format": "date-time" }
        }
      },
      "Address": {
        "type": "object",
        "required": ["city", "country", "postalCode", "state", "street"],
        "properties": {
          "city": { "type": ["string", "null"] },
          "country": { "type": ["string", "null"] },
          "postalCode": { "type": ["string", "null"] },
          "state": { "type": ["string", "null"] },
          "street": { "type": ["string", "null"] }
        }
      },
      "Doctor": {
        "type": "object",
        "required": [
          "id",
          "name",
          "legalName",
          "address",
          "location",
          "phone",
          "phoneType",
          "additionalPhones",
          "email",
          "website",
          "googleMapsUrl",
          "primaryType",
          "specialties",
          "rating",
          "reviewCount",
          "whatsappEligible",
          "verified",
          "workingHours",
          "profileUrl"
        ],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": ["string", "null"] },
          "legalName": { "type": ["string", "null"] },
          "address": { "$ref": "#/components/schemas/Address" },
          "location": {
            "oneOf": [
              { "type": "null" },
              {
                "type": "object",
                "required": ["latitude", "longitude"],
                "properties": {
                  "latitude": { "type": "number" },
                  "longitude": { "type": "number" }
                }
              }
            ]
          },
          "phone": { "type": ["string", "null"] },
          "phoneType": {
            "type": ["string", "null"],
            "enum": ["mobile", "landline", "other", null]
          },
          "additionalPhones": {
            "type": "array",
            "items": { "type": "object" },
            "maxItems": 20
          },
          "email": { "type": ["string", "null"] },
          "website": { "type": ["string", "null"], "format": "uri" },
          "googleMapsUrl": { "type": ["string", "null"], "format": "uri" },
          "primaryType": { "type": ["string", "null"] },
          "specialties": {
            "type": "array",
            "items": { "type": "string" },
            "maxItems": 50
          },
          "rating": { "type": ["number", "null"] },
          "reviewCount": { "type": ["number", "null"] },
          "whatsappEligible": {
            "type": "boolean",
            "description": "Technical reachability signal only; not consent."
          },
          "verified": { "type": "boolean" },
          "workingHours": { "type": ["object", "null"] },
          "profileUrl": { "type": "string", "format": "uri" }
        }
      },
      "DoctorPage": {
        "type": "object",
        "required": ["doctors", "page"],
        "properties": {
          "doctors": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Doctor" },
            "maxItems": 100
          },
          "page": {
            "type": "object",
            "required": ["count", "hasMore", "nextCursor"],
            "properties": {
              "count": { "type": "integer", "minimum": 0, "maximum": 100 },
              "hasMore": { "type": "boolean" },
              "nextCursor": { "type": ["string", "null"] }
            }
          }
        }
      }
    }
  }
}
