{
  "openapi": "3.1.0",
  "info": {
    "title": "NorthMock Address Generator API",
    "version": "1.3.0",
    "description": "Generate one US or Canadian test record with separate address fields, independently assembled contact values, reserved phone formats, and optional region, NYC, or exact US ZIP filtering.",
    "license": {
      "name": "Testing and educational use only"
    }
  },
  "externalDocs": {
    "description": "NorthMock API documentation",
    "url": "https://us.chatgpt.org.uk/developers/address-generator-api/"
  },
  "servers": [
    {
      "url": "https://us.chatgpt.org.uk",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Addresses",
      "description": "Region-aware address and contact test records"
    }
  ],
  "paths": {
    "/api/generate": {
      "get": {
        "tags": ["Addresses"],
        "summary": "Generate one address test record",
        "description": "Returns one record from a random or selected regional pool. Generated responses are not cached.",
        "operationId": "generateAddressRecord",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "description": "Supported two-letter US state or Canadian province or territory code.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z]{2}$",
              "examples": ["CA", "NY", "ON", "BC"]
            }
          },
          {
            "name": "city",
            "in": "query",
            "required": false,
            "description": "Supported city filter ID. The city must match state when both are supplied.",
            "schema": {
              "type": "string",
              "enum": ["nyc"]
            }
          },
          {
            "name": "zip",
            "in": "query",
            "required": false,
            "description": "Exact five-digit US ZIP. Requires a matching US state or city scope.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{5}$",
              "examples": ["43215", "06103"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Generated test record",
            "headers": {
              "Cache-Control": {
                "description": "Generated records are not cached.",
                "schema": { "type": "string", "const": "no-store" }
              },
              "Access-Control-Allow-Origin": {
                "description": "Configured CORS origin.",
                "schema": { "type": "string" }
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/GenerateResponse" }
              }
            }
          },
          "400": {
            "description": "Invalid or inconsistent region, city, or ZIP filter",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "404": {
            "description": "No fixture matches the exact ZIP in the selected pool",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "405": {
            "description": "Unsupported HTTP method",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "headers": {
              "Retry-After": {
                "description": "Seconds before retrying.",
                "schema": { "type": "string", "const": "60" }
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "500": {
            "description": "Unexpected generation failure",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "503": {
            "description": "Regional address data temporarily unavailable",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      },
      "options": {
        "tags": ["Addresses"],
        "summary": "CORS preflight",
        "operationId": "generateAddressOptions",
        "responses": {
          "204": {
            "description": "CORS preflight accepted"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "GenerateResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": ["data", "meta"],
        "properties": {
          "data": { "$ref": "#/components/schemas/GeneratedRecord" },
          "meta": { "$ref": "#/components/schemas/GenerationMeta" }
        }
      },
      "GeneratedRecord": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "address", "addressLine", "locality", "postalCode", "name", "gender",
          "email", "inboxUrl", "phone", "phoneInternational", "phoneE164",
          "state", "country", "region", "city", "filters"
        ],
        "properties": {
          "address": { "type": "string" },
          "addressLine": { "type": "string" },
          "locality": { "type": "string" },
          "postalCode": { "type": "string" },
          "name": { "type": "string" },
          "gender": { "type": "string", "enum": ["Male", "Female"] },
          "email": { "type": "string", "format": "email" },
          "inboxUrl": { "type": "string", "format": "uri" },
          "phone": { "type": "string" },
          "phoneInternational": { "type": "string" },
          "phoneE164": { "type": "string", "pattern": "^\\+1[0-9]{10}$" },
          "phoneAssignedPrefix": { "type": ["string", "null"] },
          "phoneAssignedPrefixInternational": { "type": ["string", "null"] },
          "state": { "type": "string", "pattern": "^[A-Z]{2}$" },
          "country": { "type": "string", "enum": ["US", "CA"] },
          "region": { "$ref": "#/components/schemas/Region" },
          "city": {
            "oneOf": [
              { "$ref": "#/components/schemas/City" },
              { "type": "null" }
            ]
          },
          "filters": { "$ref": "#/components/schemas/Filters" }
        }
      },
      "Region": {
        "type": "object",
        "additionalProperties": false,
        "required": ["code", "name", "country", "countryName", "path"],
        "properties": {
          "code": { "type": "string" },
          "name": { "type": "string" },
          "country": { "type": "string", "enum": ["US", "CA"] },
          "countryName": { "type": "string", "enum": ["United States", "Canada"] },
          "path": { "type": "string" }
        }
      },
      "City": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "name", "shortName", "path"],
        "properties": {
          "id": { "type": "string", "enum": ["nyc"] },
          "name": { "type": "string" },
          "shortName": { "type": "string" },
          "path": { "type": "string" }
        }
      },
      "Filters": {
        "type": "object",
        "additionalProperties": false,
        "required": ["city", "zipCode"],
        "properties": {
          "city": { "type": ["string", "null"] },
          "zipCode": { "type": ["string", "null"] }
        }
      },
      "GenerationMeta": {
        "type": "object",
        "required": ["generatedAt", "intendedUse", "namePolicy", "phonePolicy"],
        "properties": {
          "generatedAt": { "type": "string", "format": "date-time" },
          "intendedUse": { "type": "string", "const": "development-and-testing" },
          "namePolicy": { "type": "object" },
          "phonePolicy": { "type": "object" }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "additionalProperties": false,
            "required": ["code", "message"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
